我的Google文档电子表格调用以json格式返回此响应 (我只需要“行”之后的所有内容) 请查看formatted response here:)
我使用php的json_decode函数来解析数据并使用它(是的,我在php上很糟糕)这段代码返回NULL,根据文档,返回NULL “如果json不能被解码“。
$ json = file_get_contents($ jsonurl);
$ json_output = json_decode($ json);var_dump($ json_output); //返回NULL
基本上,我想要完成的是从Json响应的第一行值创建一个简单的数组。
像这样$array = {'john','John Handcock','email@yahoo.com','2929292','blanc'}
你们是天才,我非常感谢你们的见解和帮助!
回答为“sberry2A”提到吼叫,响应无效Json,google为此目的提供了Zend Json library,所以我决定解析tsv-excel版本:)
答案 0 :(得分:1)
您提供的链接中的数据不是有效的JSON。您提供的内容似乎是解码版本。你可以告诉它不是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"}]}]}}'
$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);
//输出
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 ) ) ) )
答案 1 :(得分:0)
您是否尝试从回复myData(...)
中删除回调函数?
答案 2 :(得分:0)
$json = file_get_contents($jsonfile);
$data = json_decode($json);
print_r($data);
答案 3 :(得分:0)
PEAR包Services_Json能够使用不带引号的密钥解析JSON。因此,剥离回调并使用Services_Json进行解析,我相信这将有效。