3

I am using Android Facebook SDK to get facebook friends.

After getting facebook friends I am sending it in a JSON string as input to PHP web service as given below.

JSON input

{
  "data": [
    {
      "fbUsername": "test",
      "is_app_user": "false",
      "name": "test",
      "pic_square": "https:\/\/fbcdn-profile-a.akamaihd.net\/hprofile-ak-prn2\/t5.0-1\/test.jpg",
      "uid": "456464515482",
      "userId": "42"
    }
  ]
}

When I send it via iOS appliation it works fine, but if I send it via Android it's not getting decoded from web service end.

PHP web service code is given below.

$post_body = file_get_contents('php://input');
$reqData[] = json_decode($post_body);
$userdata = $reqData[0];

In android data I am getting data in $post_body but not decoded in $reqData. But it works well in iOS application.

I am getting error as given below.

enter image description here

@$error=0;
$friendsArray = $userdata->data; // Line number 645

foreach ($friendsArray as $fbUser) // Line number 647
{
  .....
}
// where $userdata = $reqData[0];

Can anybody please suggest me what is the wrong with my coding?

Thanks in advance.

5
  • show us some lines (related to lines 645 & 647) in the file D:\wamp\...\file.php
    – ihsan
    Mar 19, 2014 at 6:10
  • I have added lines in question. Mar 19, 2014 at 8:38
  • do double check if you get the correct input $post_body = file_get_contents('php://input'); both on iOS and android.
    – ihsan
    Mar 19, 2014 at 10:21
  • Yes, I am getting correct input from both android and iOS. I am getting JSON_ERROR_UTF8 error. Mar 19, 2014 at 10:31
  • ah, there you got the specific error. try to encode the input using utf8_encode php.net/manual/en/function.utf8-encode.php
    – ihsan
    Mar 19, 2014 at 11:05

0

Your Answer

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

Browse other questions tagged or ask your own question.