api - How to decode Google spreadsheet's Json respose as a Php Array -


my google docs spreadsheet call returns response in json format
(i need after "rows") please @ formatted response here : )

i use php's json_decode function parse data , use (yes, awful @ php) code returns null, , according documentation, null returned "if json cannot decoded".

$json = file_get_contents($jsonurl);
$json_output = json_decode($json);

var_dump ($json_output); // returns null

basically, want accomplish make simple array first row values of json response.

like

$array = {'john','john handcock','email@yahoo.com','2929292','blanc'} 

you guys genius, appreciate insight , on much!

answer "sberry2a" mentions bellow, response not valid json, google offers zend json library purpose, tho decided parse tsv-excel version instead :)

the data in link provided not valid json. have provided appears decoded version. can tell in not json because array keys not quoted. instance, version should 'version'.

your data should more 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@yahoo.com"},{"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@yahoo.com"},{"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@yahoo.com ) [3] => stdclass object ( [v] => 2929292.0 [f] => 2929292 ) [4] => stdclass object ( [v] => blanc ) ) ) )  

Comments

Popular posts from this blog

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

c++ - Convert big endian to little endian when reading from a binary file -

openssl - Load PKCS#8 binary key into Ruby -