我有如下的API响应。 我这是为了解决这个问题。并得到低于回应。 $data = json_decode($response);
从维基百科api中提取具体数据
{#240 ▼
+"batchcomplete": ""
+"query": {#243 ▼
+"pages": {#234 ▼
+"171166": {#245 ▼
+"pageid": 171166
+"ns": 0
+"title": "Nepal"
+"extract": """
Nepal (/nəˈpɔːl/; Nepali: नेपाल Nepāl [neˈpal]), officially the Federal Democratic Republic of Nepal (Nepali: सङ्घीय लोकतान्त्रिक गणतन्त्र नेपाल Sanghiya Loktā ▶
The territory of Nepal has a recorded history since the Neolithic age. The name "Nepal" is first recorded in texts from the Vedic Age, the era which founded Hin ▶
Modern Nepal is a federal secular parliamentary republic. It has seven states. Nepal is a developing nation, ranking 144th on the Human Development Index (HDI) ▶
Nepal's foreign relations expanded after the Anglo-Nepal Treaty of 1923, which was recognized by the League of Nations. After a Soviet veto in 1949, Nepal was a ▶
"""
}
}
}
}
我想提取title
和content
。我该怎么做?
编辑:我曾尝试$data = json_decode($response, true);
,并通过这样var_dump($data['query']['pages'])
得到下面的结果。结果:
array:1 [▼
171166 => array:4 [▼
"pageid" => 171166
"ns" => 0
"title" => "Nepal"
"extract" => """
Nepal (/nəˈpɔːl/; Nepali: नेपाल Nepāl [neˈpal]), officially the Federal Democratic Republic of Nepal (Nepali: सङ्घीय लोकतान्त्रिक गणतन्त्र नेपाल Sanghiya Loktā ▶
The territory of Nepal has a recorded history since the Neolithic age. The name "Nepal" is first recorded in texts from the Vedic Age, the era which founded Hin ▶
Modern Nepal is a federal secular parliamentary republic. It has seven states. Nepal is a developing nation, ranking 144th on the Human Development Index (HDI) ▶
Nepal's foreign relations expanded after the Anglo-Nepal Treaty of 1923, which was recognized by the League of Nations. After a Soviet veto in 1949, Nepal was a ▶
"""
]
]
删除图像和粘贴代码.... –
https://stackoverflow.com/questions/7185288/how-to-get-wikipedia-content-using-wikipedias-api –
它没有回答我的问题@Ahmad。 – vijayrana