這是我的嘗試:獲取JSON結果到一個PHP數組中。怎麼樣?
$doc = new DOMDocument();
$jsonurl = "http://v1.syndication.nhschoices.nhs.uk/.json?apikey=xxxxxx";
$doc->load($jsonurl);
var_dump(json_decode($doc));
var_dump(json_decode($doc, true));
的輸出是2個var_dumps NULL NULL。
的JSON從URL返回看起來像這樣(後查看源代碼):
[{"Text":"Live Well","Uri":"http:\/\/v1.syndication.nhschoices.nhs.uk\/livewell?apikey=xxxxx"},{"Text":"Conditions","Uri":"http:\/\/v1.syndication.nhschoices.nhs.uk\/conditions?apikey=xxxxx"},{"Text":"Organisations","Uri":"http:\/\/v1.syndication.nhschoices.nhs.uk\/organisations?apikey=xxxxx"},{"Text":"Carers Direct","Uri":"http:\/\/v1.syndication.nhschoices.nhs.uk\/carersdirect?apikey=xxxxx"}]
這是有效的?
什麼是var_dump($ doc)輸出。它有效的JSON? – Belinda 2011-03-11 11:51:45
爲什麼要將JSON加載到DOMDocument中? JSON!= XML。 – mdm 2011-03-11 11:52:29
只需通過http://www.jsonlint.com/將JSON置於有效位置即可:/ – JohnnyBizzle 2011-03-11 13:25:32