[英]how to decode this JSON string?
this is what i get as a string from a feed finder url (JSON Encoded):这是我从提要查找器 url (JSON 编码) 中得到的字符串:
{
"updated": 1265787927,
"id": "http://www.google.com/reader/api/0/feed-finder?q\u003dhttp://itcapsule.blogspot.com/\u0026output\u003djson",
"title": "Feed results for \"http://itcapsule.blogspot.com/\"",
"self": [{
"href": "http://www.google.com/reader/api/0/feed-finder?q\u003dhttp://itcapsule.blogspot.com/\u0026output\u003djson"
}],
"feed": [{
"href": "http://itcapsule.blogspot.com/feeds/posts/default"
}]
}
How can i decode it using json_decode() function in php and get the last array element ("feed") ?我如何使用 php 中的 json_decode() 函数对其进行解码并获取最后一个数组元素(“feed”)? i tried it with the following code but no luck
我用下面的代码试过了,但没有运气
$json = file_get_contents("http://www.google.com/reader/api/0/feed-finder?q=http://itcapsule.blogspot.com/&output=json");
$ar = (array)(json_decode($json,true));
print_r $ar;
Please help ..请帮忙 ..
$array = json_decode($json, true);
$feed = $array['feed'];
Note that json_decode()
already returns an array when you call it with true
as second parameter.请注意,当您使用
true
作为第二个参数调用它时, json_decode()
已经返回一个数组。
Update:更新:
As the value of feed
in JSON作为 JSON 中
feed
的值
"feed":[{"href":"http://itcapsule.blogspot.com/feeds/posts/default"}]
is an array of objects, the content of $array['feed']
is:是一个对象数组,
$array['feed']
是:
Array
(
[0] => Array
(
[href] => http://itcapsule.blogspot.com/feeds/posts/default
)
)
To get the URL you have to access the array with $array['feed'][0]['href']
or $feed[0]['href']
.要获取 URL,您必须使用
$array['feed'][0]['href']
或$feed[0]['href']
访问数组。
But this is basic handling of arrays.但这是对数组的基本处理。 Maybe the Arrays documentation helps you.
也许Arrays 文档可以帮助您。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.