这可能是一个明显的答案,我只是没有得到,因为我已经在这几个小时了。所以从Wikipedia API query我得到了这个回复
{"batchcomplete":"","continue":{"sroffset":1,"continue":"-||"},"query":{"searchinfo":{"totalhits":173918},"search":[{"ns":0,"title":"Google","snippet":"search engine, see Google Search. For other uses, see Google (disambiguation). Not to be confused with Goggle\u00a0or Googol. Google Inc. is an American","size":143977,"wordcount":13927,"timestamp":"2015-11-25T08:44:48Z"}]}}
我已将其转换为此php数组
Array
(
[batchcomplete] =>
[continue] => Array
(
[sroffset] => 1
[continue] => -||
)
[query] => Array
(
[searchinfo] => Array
(
[totalhits] => 173918
)
[search] => Array
(
[0] => Array
(
[ns] => 0
[title] => Google
[snippet] => search engine, see Google Search. For other uses, see Google (disambiguation). Not to be confused with Goggle or Googol. Google Inc. is an American
[size] => 143977
[wordcount] => 13927
[timestamp] => 2015-11-25T08:44:48Z
)
)
)
)
我正在尝试使用此代码从数组中提取Title实体
echo $array->query->search->0->title;
我做错了什么?
答案 0 :(得分:0)
您使用的是stdClass对象,
echo $array->query->search->0->title;
将->
替换为[]
echo $array['query']['search'][0]['title'];