こんにちは私はBing Web検索APIを使用していますので、PHPを使用してJSONをhtmlに翻訳すると助けが必要です。 foreach()とif()ステートメントを使って選択的なスタッフを印刷できるようになりました。私は他のエントランスで見てきましたが、何が問題か分かりません。ここで foreachを使用してJSONを多次元配列で出力する
は、JSONの例である:私は次のエラーを取得しています$links = json_decode($json, TRUE);
foreach ($links['webPages'] as $j => $v) {
if($j=="value"){
foreach ($v as $k => $w) {
print $k . ": " . $w;
}
}
}
:私は、私は次のPHPコードを使用しています内部の「ウェブページ」をいくつかのものを印刷したい
{
"_type": "SearchResponse",
"queryContext": {
"originalQuery": "Microsoft Cognitive Services"
},
"webPages": {
"webSearchUrl": "https:\/\/www.bing.com\/search?q=Microsoft+Cognitive+Services",
"totalEstimatedMatches": 2320000,
"value": [
{
"id": "https:\/\/api.cognitive.microsoft.com\/api\/v7\/#WebPages.0",
"name": "Cognitive Services | Microsoft Azure",
"url": "https:\/\/azure.microsoft.com\/es-es\/services\/cognitive-services\/",
"displayUrl": "https:\/\/azure.microsoft.com\/es-es\/services\/cognitive-services",
"snippet": "Agregue funcionalidades de visi\u00f3n, voz, lenguaje y conocimiento a sus aplicaciones mediante las API de inteligencia artificial de Cognitive Services.",
"dateLastCrawled": "2017-11-22T05:45:00.0000000Z"
},
{
"id": "https:\/\/api.cognitive.microsoft.com\/api\/v7\/#WebPages.1",
"name": "Microsoft Cognitive Services: Componentes del Servicio ...",
"url": "https:\/\/azure.microsoft.com\/es-es\/support\/legal\/cognitive-services-components\/",
"displayUrl": "https:\/\/azure.microsoft.com\/es-es\/support\/legal\/cognitive-services...",
"snippet": "Revise el uso de los t\u00e9rminos de Microsoft Cognitive Services: Componentes del Servicio.",
"dateLastCrawled": "2017-11-21T02:34:00.0000000Z"
},
{
"id": "https:\/\/api.cognitive.microsoft.com\/api\/v7\/#WebPages.2",
"name": "Microsoft Trust Center | Microsoft Cognitive Services",
"url": "https:\/\/www.microsoft.com\/en-us\/trustcenter\/cloudservices\/cognitiveservices",
"displayUrl": "https:\/\/www.microsoft.com\/...\/cloudservices\/cognitiveservices",
"snippet": "Microsoft Cognitive Services is a collection of intelligent APIs that allow systems to understand and interpret people\u2019s needs by using natural methods ...",
"dateLastCrawled": "2017-11-18T16:46:00.0000000Z"
},
{
"id": "https:\/\/api.cognitive.microsoft.com\/api\/v7\/#WebPages.3",
"name": "Cognitive Services | Microsoft Azure",
"url": "https:\/\/azure.microsoft.com\/en-us\/services\/cognitive-services\/",
"displayUrl": "https:\/\/azure.microsoft.com\/en-us\/services\/cognitive-services",
"snippet": "Add vision, speech, language and knowledge capabilities to your apps with artificial intelligence APIs from Cognitive Services. Explore our APIs today.",
"dateLastCrawled": "2017-11-22T02:20:00.0000000Z"
},
{
"id": "https:\/\/api.cognitive.microsoft.com\/api\/v7\/#WebPages.4",
"name": "Cognitive Service Try experience | Microsoft Azure",
"url": "https:\/\/azure.microsoft.com\/en-us\/try\/cognitive-services\/",
"displayUrl": "https:\/\/azure.microsoft.com\/en-us\/try\/cognitive-services",
"snippet": "Microsoft Cognitive Services Try experience lets you build apps with powerful algorithms using just a few lines of code through a 30 day trial.",
"dateLastCrawled": "2017-11-21T02:42:00.0000000Z"
},
{
"id": "https:\/\/api.cognitive.microsoft.com\/api\/v7\/#WebPages.5",
"name": "Cognitive Services Directory | Microsoft Azure",
"url": "https:\/\/azure.microsoft.com\/en-us\/services\/cognitive-services\/directory\/",
"displayUrl": "https:\/\/azure.microsoft.com\/...\/services\/cognitive-services\/directory",
"snippet": "Learn more about Cognitive Services and manage them in the Azure cloud, or test them with temporary access.",
"dateLastCrawled": "2017-11-21T21:14:00.0000000Z"
},
{
"id": "https:\/\/api.cognitive.microsoft.com\/api\/v7\/#WebPages.6",
"name": "What is Microsoft Cognitive Services? | Microsoft Docs",
"url": "https:\/\/docs.microsoft.com\/en-us\/azure\/cognitive-services\/Welcome",
"displayUrl": "https:\/\/docs.microsoft.com\/en-us\/azure\/cognitive-services\/Welcome",
"snippet": "Microsoft Cognitive Services is a set of APIs, SDKs, and services that you can use with Microsoft Azure that make applications more intelligent, engaging ...",
"dateLastCrawled": "2017-11-21T17:40:00.0000000Z",
"searchTags": [
{
"name": "search.ms_sitename",
"content": "\"Docs\"; docs"
},
{
"name": "search.ms_docsetname",
"content": "\"azure-documents\"; azure; documents"
},
{
"name": "search.ms_product",
"content": "\"Azure\"; azure"
}
]
},
{
"id": "https:\/\/api.cognitive.microsoft.com\/api\/v7\/#WebPages.7",
"name": "Microsoft Cognitive Services",
"url": "https:\/\/westus.dev.cognitive.microsoft.com\/docs\/services\/TextAnalytics.V2.0\/operations\/56f30ceeeda5650db055a3c7",
"displayUrl": "https:\/\/westus.dev.cognitive.microsoft.com\/docs\/services\/Text...",
"snippet": "Text Analytics API. The Text Analytics API is a suite of text analytics web services built with best-in-class Microsoft machine learning algorithms.",
"dateLastCrawled": "2017-11-22T13:25:00.0000000Z"
}
]
}
:
Notice: Array to string conversion
そして、それは印刷します。
0: Array
1: Array
...
7: Array
ありがとうございます。
コード内で ')('のvar_dumpを振りかけてみ - あなたは何が起こっているか見てみましょうべきです。 –