Reputation: 7418
My google Docs Spreadsheet call returns this response in the json format
(I only need everything after "rows")
please look at the formatted response here : )
I use php's json_decode function to parse the data and use it (Yes, I am awful at php) This code returns NULL, and according to the documentation, NULL is returned "if the json cannot be decoded".
$json = file_get_contents($jsonurl);
$json_output = json_decode($json);var_dump ($json_output); // Returns NULL
Basically, what i want to accomplish is to make a simple array from the first row values of the Json response.
like this
$array = {'john','John Handcock','[email protected]','2929292','blanc'}
You guys are genius, I would appreciate your insight and help on this very much!
Answer as "sberry2A" mentions bellow, the response is not valid Json, google offers the Zend Json library for this purpose, tho I decided to parse the tsv-excel version instead :)
Upvotes: 1
Views: 2552
Reputation: 13936
The PEAR package Services_Json is able to parse JSON with unquoted keys. So, strip the callback and parse with Services_Json and I believe that will work.
http://mike.teczno.com/JSON/doc/
Upvotes: 0
Reputation: 961
$json = file_get_contents($jsonfile);
$data = json_decode($json);
print_r($data);
Upvotes: 0
Reputation: 132018
The data in the link you provided is not valid JSON. What you have provided appears to be the decoded version. You can tell that is in not JSON because the array keys are not quoted. For instance, version should be 'version'.
Your data should look more like this
'{"version":"0.6","reqId":"requestIDnumber","status":"ok","sig":"65724392","table":{"cols":[{"id":"A","label":"slug","type":"string", "pattern":""},{"id":"B","label":"name","type":"string","pattern":""},{"id":"C","label":"email","type":"string","pattern":""},{"id":"D","label" :"nsid","type":"number","pattern":"#0.###############"},{"id":"E","label":"theme","type":"string","pattern":""}],"rows":[{"c":[{"v":"mo"},{"v": "Mohammad Taheri"},{"v":"[email protected]"},{"v":"2929292.0","f":"2929292"},{"v":"blanc"}]}]}}'
$json = '{"version":"0.6","reqId":"requestIDnumber","status":"ok","sig":"65724392","table":{"cols":[{"id":"A","label":"slug","type":"string", "pattern":""},{"id":"B","label":"name","type":"string","pattern":""},{"id":"C","label":"email","type":"string","pattern":""},{"id":"D","label" :"nsid","type":"number","pattern":"#0.###############"},{"id":"E","label":"theme","type":"string","pattern":""}],"rows":[{"c":[{"v":"mo"},{"v": "Mohammad Taheri"},{"v":"[email protected]"},{"v":"2929292.0","f":"2929292"},{"v":"blanc"}]}]}}';
$data = json_decode($json);
print_r($data->table->rows);
//output
Array ( [0] => stdClass Object ( [c] => Array ( [0] => stdClass Object ( [v] => mo ) [1] => stdClass Object ( [v] => Mohammad Taheri ) [2] => stdClass Object ( [v] => [email protected] ) [3] => stdClass Object ( [v] => 2929292.0 [f] => 2929292 ) [4] => stdClass Object ( [v] => blanc ) ) ) )
Upvotes: 1
Reputation: 5902
Did you try removing the callback function from the response myData(...)
?
Upvotes: 0