0

目前我尝试 Azure 搜索。

我设法在索引中插入文档,现在我想解析我的结果。

我的代码如下所示:

<?php
$url ="";
   $url .="https://mywebsite.search.windows.net/indexes/test/docs";
   $url .= "?search=";
   $url .= $keyword;
   $url .= "&api-version=2014-07-31-Preview";
   print $url;


   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL,$url);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_TIMEOUT, 60);
   curl_setopt($ch, CURLOPT_HTTPHEADER, array(
           'api-key: mytoken',
           'Accept: application/json',
     ));

   $data = curl_exec($ch);

   if (curl_errno($ch)) {
   print "Error: " . curl_error($ch);
   } else 
   {
   // Show me the result
   print var_dump($data);
   curl_close($ch);
   }
?>

我的程序运行良好,但我无法解析如下所示的结果:

string(633) "{"@odata.context":" https://mywebsite.search.windows.net/indexes ('adventurehotel')/$metadata#docs(hotelId,baseRate,description,hotelName,category,tags,停车包括,吸烟允许,lastRenovationDate,rating,location)","value":[{"@search.score":0.16137227,"hotelId":"1","baseRate":199.0,"description":"镇上最好的酒店","hotelName":"Fancy Stay","category":"Luxury","tags":["pool","view","wifi","concierge"],"parkingIncluded":false,"SmokingAllowed" :false,"lastRenovationDate":"2010-06-27T00:00:00Z","rating":5,"location":{"type":"Point","坐标":[-122.131577,47.678581],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}}}]}"

提前致谢。

4

1 回答 1

1

只需json_decode它,它只是一个json字符串。

json_decode,如果true作为第二个参数调用,将为您提供要解析的字符串的关联数组表示。字符串本身应该是一个有效的json字符串,否则您将得到null函数结果。

请注意,从 php 5.5 及更高版本开始,由于其许可证,json 扩展应与主 php 安装分开安装。

于 2014-11-17T12:24:47.807 回答