大家好我有一个PHP的问题,请帮助我解决这个问题。阅读Google电子表格的JSON
我想使用PHP从Google Spreadsheet中读取数据,并搜索了一些网页并获得了JSON格式的表格。但我无法用PHP读取我的数据。
这是我的PHP代码:
<?php
echo "<h1>Hello, PHP!</h1>";
$url = "https://spreadsheets.google.com/feeds/list/0Aqglj65pqAwmdEh4a1otT3lmYnN0TGV1Q2JkdndVUnc/od6/public/basic?hl=en_US&alt=json";
$data = file_get_contents($url);
echo $data;
/*What can I do here to read the values of Sensor1,Sensor2,Sensor3 in result ? */
?>
,这是结果:
{ "version": "1.0", "encoding": "UTF-8", "feed": { "xmlns": "http://www.w3.org/2005/Atom", "xmlns$openSearch": "http://a9.com/-/spec/opensearchrss/1.0/", "xmlns$gsx": "http://schemas.google.com/spreadsheets/2006/extended", "id": { "$t": "https://spreadsheets.google.com/feeds/list/1X9ofybaA0PiXE-rCec-m1CuNgkPENqWFogWjgoVXZRc/od6/public/values" }, "updated": { "$t": "2014-10-07T22:49:06.978Z" }, "category": [ { "scheme": "http://schemas.google.com/spreadsheets/2006", "term": "http://schemas.google.com/spreadsheets/2006#list" } ], "title": { "type": "text", "$t": "Sheet1" }, "link": [ { "rel": "alternate", "type": "application/atom+xml", "href": "https://docs.google.com/spreadsheets/d/1X9ofybaA0PiXE-rCec-m1CuNgkPENqWFogWjgoVXZRc/pubhtml" }, { "rel": "http://schemas.google.com/g/2005#feed", "type": "application/atom+xml", "href": "https://spreadsheets.google.com/feeds/list/1X9ofybaA0PiXE-rCec-m1CuNgkPENqWFogWjgoVXZRc/od6/public/values" }, { "rel": "http://schemas.google.com/g/2005#post", "type": "application/atom+xml", "href": "https://spreadsheets.google.com/feeds/list/1X9ofybaA0PiXE-rCec-m1CuNgkPENqWFogWjgoVXZRc/od6/public/values" }, { "rel": "self", "type": "application/atom+xml", "href": "https://spreadsheets.google.com/feeds/list/1X9ofybaA0PiXE-rCec-m1CuNgkPENqWFogWjgoVXZRc/od6/public/values?alt\u003djson" } ], "author": [ { "name": { "$t": "lethanhtrieuK36" }, "email": { "$t": "[email protected]" } } ], "openSearch$totalResults": { "$t": "9" }, "openSearch$startIndex": { "$t": "1" }, "entry": [ { "id": { "$t": "https://spreadsheets.google.com/feeds/list/1X9ofybaA0PiXE-rCec-m1CuNgkPENqWFogWjgoVXZRc/od6/public/values/cokwr" }, "updated": { "$t": "2014-10-07T22:49:06.978Z" }, "category": [ { "scheme": "http://schemas.google.com/spreadsheets/2006", "term": "http://schemas.google.com/spreadsheets/2006#list" } ], "title": { "type": "text", "$t": "10/4/2014 15:56:01" }, "content": { "type": "text", "$t": "sensor1: demo data, sensor2: ON, sensor3: NOW" }, "link": [ { "rel": "self", "type": "application/atom+xml", "href": "https://spreadsheets.google.com/feeds/list/1X9ofybaA0PiXE-rCec-m1CuNgkPENqWFogWjgoVXZRc/od6/public/values/cokwr" } ], "gsx$timestamp": { "$t": "10/4/2014 15:56:01" }, "gsx$sensor1": { "$t": "demo data" }, "gsx$sensor2": { "$t": "ON" }, "gsx$sensor3": { "$t": "NOW" } }, { "id": { "$t": "https://spreadsheets.google.com/feeds/list/1X9ofybaA0PiXE-rCec-m1CuNgkPENqWFogWjgoVXZRc/od6/public/values/cpzh4" }, "updated": { "$t": "2014-10-07T22:49:06.978Z" }, "category": [ { "scheme": "http://schemas.google.com/spreadsheets/2006", "term": "http://schemas.google.com/spreadsheets/2006#list" } ], "title": { "type": "text", "$t": "10/4/2014 15:56:05" }, "content": { "type": "text", "$t": "sensor1: 22, sensor2: OFF, sensor3: DO" }, "link": [ { "rel": "self", "type": "application/atom+xml", "href": "https://spreadsheets.google.com/feeds/list/1X9ofybaA0PiXE-rCec-m1CuNgkPENqWFogWjgoVXZRc/od6/public/values/cpzh4" } ], "gsx$timestamp": { "$t": "10/4/2014 15:56:05" }, "gsx$sensor1": { "$t": "22" }, "gsx$sensor2": { "$t": "OFF" }, "gsx$sensor3": { "$t": "DO" } }, { "id": { "$t": "https://spreadsheets.google.com/feeds/list/1X9ofybaA0PiXE-rCec-m1CuNgkPENqWFogWjgoVXZRc/od6/public/values/cre1l" }, "updated": { "$t": "2014-10-07T22:49:06.978Z" }, "category": [ { "scheme": "http://schemas.google.com/spreadsheets/2006", "term": "http://schemas.google.com/spreadsheets/2006#list" } ], "title": { "type": "text", "$t": "10/4/2014 15:56:05" }, "content": { "type": "text", "$t": "sensor1: 34, sensor2: ON, sensor3: SOME" }, "link": [ { "rel": "self", "type": "application/atom+xml", "href": "https://spreadsheets.google.com/feeds/list/1X9ofybaA0PiXE-rCec-m1CuNgkPENqWFogWjgoVXZRc/od6/public/values/cre1l" } ], "gsx$timestamp": { "$t": "10/4/2014 15:56:05" }, "gsx$sensor1": { "$t": "34" }, "gsx$sensor2": { "$t": "ON" }, "gsx$sensor3": { "$t": "SOME" } }, { "id": { "$t": "https://spreadsheets.google.com/feeds/list/1X9ofybaA0PiXE-rCec-m1CuNgkPENqWFogWjgoVXZRc/od6/public/values/chk2m" }, "updated": { "$t": "2014-10-07T22:49:06.978Z" }, "category": [ { "scheme": "http://schemas.google.com/spreadsheets/2006", "term": "http://schemas.google.com/spreadsheets/2006#list" } ], "title": { "type": "text", "$t": "10/4/2014 15:56:29" }, "content": { "type": "text", "$t": "sensor1: 33, sensor2: 27, sensor3: THING" }, "link": [ { "rel": "self", "type": "application/atom+xml", "href": "https://spreadsheets.google.com/feeds/list/1X9ofybaA0PiXE-rCec-m1CuNgkPENqWFogWjgoVXZRc/od6/public/values/chk2m" } ], "gsx$timestamp": { "$t": "10/4/2014 15:56:29" }, "gsx$sensor1": { "$t": "33" }, "gsx$sensor2": { "$t": "27" }, "gsx$sensor3": { "$t": "THING" } }, { "id": { "$t": "https://spreadsheets.google.com/feeds/list/1X9ofybaA0PiXE-rCec-m1CuNgkPENqWFogWjgoVXZRc/od6/public/values/ciyn3" }, "updated": { "$t": "2014-10-07T22:49:06.978Z" }, "category": [ { "scheme": "http://schemas.google.com/spreadsheets/2006", "term": "http://schemas.google.com/spreadsheets/2006#list" } ], "title": { "type": "text", "$t": "10/4/2014 15:56:47" }, "content": { "type": "text", "$t": "sensor1: MY, sensor2: 29, sensor3: undefined" }, "link": [ { "rel": "self", "type": "application/atom+xml", "href": "https://spreadsheets.google.com/feeds/list/1X9ofybaA0PiXE-rCec-m1CuNgkPENqWFogWjgoVXZRc/od6/public/values/ciyn3" } ], "gsx$timestamp": { "$t": "10/4/2014 15:56:47" }, "gsx$sensor1": { "$t": "MY" }, "gsx$sensor2": { "$t": "29" }, "gsx$sensor3": { "$t": "undefined" } }, { "id": { "$t": "https://spreadsheets.google.com/feeds/list/1X9ofybaA0PiXE-rCec-m1CuNgkPENqWFogWjgoVXZRc/od6/public/values/ckd7g" }, "updated": { "$t": "2014-10-07T22:49:06.978Z" }, "category": [ { "scheme": "http://schemas.google.com/spreadsheets/2006", "term": "http://schemas.google.com/spreadsheets/2006#list" } ], "title": { "type": "text", "$t": "10/4/2014 15:56:48" }, "content": { "type": "text", "$t": "sensor1: DATA, sensor2: WORK, sensor3: undefined" }, "link": [ { "rel": "self", "type": "application/atom+xml", "href": "https://spreadsheets.google.com/feeds/list/1X9ofybaA0PiXE-rCec-m1CuNgkPENqWFogWjgoVXZRc/od6/public/values/ckd7g" } ], "gsx$timestamp": { "$t": "10/4/2014 15:56:48" }, "gsx$sensor1": { "$t": "DATA" }, "gsx$sensor2": { "$t": "WORK" }, "gsx$sensor3": { "$t": "undefined" } }, { "id": { "$t": "https://spreadsheets.google.com/feeds/list/1X9ofybaA0PiXE-rCec-m1CuNgkPENqWFogWjgoVXZRc/od6/public/values/clrrx" }, "updated": { "$t": "2014-10-07T22:49:06.978Z" }, "category": [ { "scheme": "http://schemas.google.com/spreadsheets/2006", "term": "http://schemas.google.com/spreadsheets/2006#list" } ], "title": { "type": "text", "$t": "10/4/2014 15:56:53" }, "content": { "type": "text", "$t": "sensor1: 56, sensor2: DATABASE, sensor3: undefined" }, "link": [ { "rel": "self", "type": "application/atom+xml", "href": "https://spreadsheets.google.com/feeds/list/1X9ofybaA0PiXE-rCec-m1CuNgkPENqWFogWjgoVXZRc/od6/public/values/clrrx" } ], "gsx$timestamp": { "$t": "10/4/2014 15:56:53" }, "gsx$sensor1": { "$t": "56" }, "gsx$sensor2": { "$t": "DATABASE" }, "gsx$sensor3": { "$t": "undefined" } }, { "id": { "$t": "https://spreadsheets.google.com/feeds/list/1X9ofybaA0PiXE-rCec-m1CuNgkPENqWFogWjgoVXZRc/od6/public/values/cyevm" }, "updated": { "$t": "2014-10-07T22:49:06.978Z" }, "category": [ { "scheme": "http://schemas.google.com/spreadsheets/2006", "term": "http://schemas.google.com/spreadsheets/2006#list" } ], "title": { "type": "text", "$t": "10/4/2014 15:56:59" }, "content": { "type": "text", "$t": "sensor1: NUMBER, sensor2: 27, sensor3: undefined" }, "link": [ { "rel": "self", "type": "application/atom+xml", "href": "https://spreadsheets.google.com/feeds/list/1X9ofybaA0PiXE-rCec-m1CuNgkPENqWFogWjgoVXZRc/od6/public/values/cyevm" } ], "gsx$timestamp": { "$t": "10/4/2014 15:56:59" }, "gsx$sensor1": { "$t": "NUMBER" }, "gsx$sensor2": { "$t": "27" }, "gsx$sensor3": { "$t": "undefined" } }, { "id": { "$t": "https://spreadsheets.google.com/feeds/list/1X9ofybaA0PiXE-rCec-m1CuNgkPENqWFogWjgoVXZRc/od6/public/values/cztg3" }, "updated": { "$t": "2014-10-07T22:49:06.978Z" }, "category": [ { "scheme": "http://schemas.google.com/spreadsheets/2006", "term": "http://schemas.google.com/spreadsheets/2006#list" } ], "title": { "type": "text", "$t": "10/4/2014 15:56:59" }, "content": { "type": "text", "$t": "sensor1: 56, sensor2: CODE, sensor3: OK" }, "link": [ { "rel": "self", "type": "application/atom+xml", "href": "https://spreadsheets.google.com/feeds/list/1X9ofybaA0PiXE-rCec-m1CuNgkPENqWFogWjgoVXZRc/od6/public/values/cztg3" } ], "gsx$timestamp": { "$t": "10/4/2014 15:56:59" }, "gsx$sensor1": { "$t": "56" }, "gsx$sensor2": { "$t": "CODE" }, "gsx$sensor3": { "$t": "OK" } } ] } }
当我使用网上JSON查看器返回:
请帮助我解决这个问题。谢谢大家!
@pnuts哦,对不起!这是我的错误!我删除它,先生!如果你知道它,请帮助我! – 2014-10-08 00:07:49