herghost Posted January 6, 2012 Share Posted January 6, 2012 Hi all, I am sure this is simple, but I just can't wrap my head around a suitable way of doing this! Basically I have my JSON result as something like : Array ( [result] => success [source] => gotBits [success] => 64 ) What I simply want to do is get the [success] output and store it as a variable. I have been looking at json_decode, but I cant find any examples for arrays, just strings? Can you push me in the right direction? Quote Link to comment https://forums.phpfreaks.com/topic/254464-first-steps-in-json/ Share on other sites More sharing options...
scootstah Posted January 6, 2012 Share Posted January 6, 2012 JSON can't be an array... it is a string. It looks like this: {"one":1,"two":2,"three":3} Using json_decode, you convert the JSON into an array. Quote Link to comment https://forums.phpfreaks.com/topic/254464-first-steps-in-json/#findComment-1304739 Share on other sites More sharing options...
dharmeshpat Posted January 6, 2012 Share Posted January 6, 2012 hi herghost are u getting json result from ajax call from php page can u explain me bit about this i think i can help u out for the same Quote Link to comment https://forums.phpfreaks.com/topic/254464-first-steps-in-json/#findComment-1304741 Share on other sites More sharing options...
herghost Posted January 6, 2012 Author Share Posted January 6, 2012 Hi mate, its from a PHP page that calls a game server api. I think I understand that I have the output of the array as a string??? Quote Link to comment https://forums.phpfreaks.com/topic/254464-first-steps-in-json/#findComment-1304742 Share on other sites More sharing options...
herghost Posted January 6, 2012 Author Share Posted January 6, 2012 Basically I am doing this: <?php $json = new MYCALL($host, $port, $username, $password, $salt); print_r($json->call('getBits',Array())); ?> Which prints the original string, basically how do I just take the result of [success]? Quote Link to comment https://forums.phpfreaks.com/topic/254464-first-steps-in-json/#findComment-1304752 Share on other sites More sharing options...
dharmeshpat Posted January 6, 2012 Share Posted January 6, 2012 Hi dude still i m not completely cleared but If you are getting value in an array format than u don't u store it in a variable and than use that variable to get that data example $valueHolder = $json->call('getBits',Array()); print_r($valueHolder['success']); Quote Link to comment https://forums.phpfreaks.com/topic/254464-first-steps-in-json/#findComment-1304754 Share on other sites More sharing options...
herghost Posted January 6, 2012 Author Share Posted January 6, 2012 Thats exactly what I was aiming at! Cheers! Quote Link to comment https://forums.phpfreaks.com/topic/254464-first-steps-in-json/#findComment-1304755 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.