1

我的 google Docs Spreadsheet 调用以 json 格式返回此响应
(我只需要“行”之后的所有内容)请在此处查看格式化响应:)

我使用 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,谷歌为此目的提供了Zend Json 库,但我决定改为解析 tsv-excel 版本:)

4

4 回答 4

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 ) ) ) ) 
于 2010-01-11T19:52:04.790 回答
0
$json = file_get_contents($jsonfile);
$data = json_decode($json);
print_r($data);
于 2010-01-12T13:51:46.143 回答
0

PEAR 包 Services_Json 能够使用不带引号的键解析 JSON。因此,剥离回调并使用 Services_Json 进行解析,我相信这会起作用。

http://mike.teczno.com/JSON/doc/

于 2010-06-09T01:08:04.447 回答
0

您是否尝试从响应中删除回调函数myData(...)

于 2010-01-11T19:56:00.700 回答