以下是JSON API调用的结果:
[{"title":"Teqpad.com|| Find Pageviews,Visits,Visitors,Unique Visitors,Website Worth...","url":"http:\/\/www.teqpad.com\/","top_tags":{"analytics":64,"statistics":57,"tools":43,"seo":41,"traffic":40,"search":22,"web":20,"blog":18,"blogging":14,"website":13}}]
我想仅提取top_tags
例如:
analytics,statistics,tools,seo,traffic,search
如何使用json_decode()
?
答案 0 :(得分:2)
您的JSON格式错误,top_tags
键引用了格式错误的对象(键,但没有值) - 它应该引用一个数组,如下所示:
[{"title":"Teqpad.com|| Find Pageviews,Visits,Visitors,Unique Visitors,Website Worth...","url":"http:\/\/www.teqpad.com\/","top_tags":["analytics","statistics","tools","seo","traffic","search","web","blog","blogging","website"]}
然后使用以下代码解析它:
$json = ...
$obj = json_decode($json);
$top_tags = $obj[0]->top_tags;
print_r($top_tags);
答案 1 :(得分:0)
$obj = json_decode($json, true);
$top_tags = array_keys($obj[0]['top_tags']);
print_r($top_tags);