0

I've got a really weird problem and I can't figure out why. The situation is quite simple. My Android app uploads JSON data to a php script on my server. Right now I am trying to parse the data.

This is the JSON-Array passed to the script (via httpPost.setEntity ()):

[{"friends_with_accepted":"false","friends_with_synced":"false","friends_with_second_id":"5","friends_with_first_id":"6"}]

This is the php script:

<?php
// array for JSON response
$response = array();

$json = file_get_contents ('php://input');
$jsonArray = json_decode ($json, true);
foreach ($jsonArray as $jsonObject) {
    $firstId   = $jsonObject['friends_with_first_id'];
    $accepted = $jsonObject ['friends_with_accepted'];
    $secondId = $jsonObject ['friends_with_second_id'];
    $synced   = $jsonObject ['friends_with_synced'];

    echo "accepted: ".$accepted."synced: ".$synced;
} ?>

And this is the response I get from the script:

accepted: synced: false

Why is the "synced" property correctly passed, but not the "accepted" property?? I can't see the difference. Btw, firstId and secondId are parsed correctly as well.

3
  • Looks strange - have you done a var_dump of $accepted and $synced to compare? Commented Feb 12, 2014 at 21:53
  • yes, i compared them, var_dump($accepted,$synced) gave me the result: NULL string(5) "false" Commented Feb 12, 2014 at 21:57
  • Looks fine: codepad.org/JmvUmwBe Commented Feb 12, 2014 at 21:59

1 Answer 1

1

Okay, i just found the problem:

Instead of

$accepted = $jsonObject ['friends_with_accepted'];

I deleted the space between jsonObject and the bracket

$accepted = $jsonObject['friends_with_accepted'];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.