0

I have a Query string

{ "id": "105201322211272730088", "name": "Rayidi Radha Krishna", "given_name": "Rayidi", "family_name": "Radha Krishna", "link": "https://plus.google.com/105201322211272730088", "picture": "https://lh3.googleusercontent.com/-UTEdowBnUUE/AAAAAAAAAAI/AAAAAAAABd0/FrCv9VX1Pp4/photo.jpg", "gender": "male", "birthday": "0000-09-23", "locale": "en" }

I want to convert this Query string to an array. thanks in advance.

Edited by rayidi: Details

3
Contributors
8
Replies
13
Views
5 Years
Discussion Span
Last Post by blocblue
1

This looks like JSON, try json_decode.

Votes + Comments
Your post impressing me since i was joined in Daniweb. Thank you
0

Dear Pritaes, thanks for the help. I realised that an JSON string.
I tried

$jsn = var_dump(json_decode($xmlresponse));

Response:

object(stdClass)#2 (9) { ["id"]=> string(21) "105201322211272730088" ["name"]=> string(20) "Rayidi Radha Krishna" ["given_name"]=> string(6) "Rayidi" ["family_name"]=> string(13) "Radha Krishna" ["link"]=> string(45) "https://plus.google.com/105201322211272730088" ["picture"]=> string(92) "https://lh3.googleusercontent.com/-UTEdowBnUUE/AAAAAAAAAAI/AAAAAAAABd0/FrCv9VX1Pp4/photo.jpg" ["gender"]=> string(4) "male" ["birthday"]=> string(10) "0000-09-23" ["locale"]=> string(2) "en" }

Now i'm not able to retreve the array. Basically i'm not aware of Arrays. I want to display

Firstname : Radha Krishna, Surname : Rayidi, Gender : male, Birthday : 0000-09-23

Please help me.

0
$values = json_decode($xmlresponse);
echo $values['name'];
echo $values['given_name'];
echo $values['birthday'];
0

Fatal error: Cannot use object of type stdClass as array in /home/student/public_html/api/validate.php on line 102

The error comming while compiling.

1

/home/student/public_html/api/validate.php on line 102

And which one is line 102?

Votes + Comments
echo $values['name']; is in line 102
2

The original string is for a JSON encoded object not an array.

To use the output as an array, you would need to convert it to an array. Notice the second argument for json_decode is true.

var_dump(json_decode($json, true));

Edited by blocblue

Votes + Comments
Thnx .. Its worked
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.