我正在使用 Zillow API 来获取搜索结果,但遇到了障碍。我正在使用他们的 GetSearchResults 工具,但出现错误:
试图获取非对象的属性
在我使用->
符号从 XML 获取值的行上。我已经阅读了关于它的讨论,也许我做错了符号,但我没有看到任何错误。如何从这个对象获取数据?
这是我当前的代码。
<?php
$zillow_id = 'X1-ZWz19g3j9ffabv_7galu';
$search = isset($_GET['5411 lydia ave'])?$_GET['5411 lydia ave']:"";
$citystate = isset($_GET['kansascitymo64110'])?$_GET['kansascitymo64110']:"";
$address = urlencode($search);
$citystatezip = urlencode($citystate);
$url = "http://www.zillow.com/webservice/GetSearchResults.htm?zws-id=$zillow_id&address=$address&citystatezip=$citystatezip";
$result = file_get_contents($url);
$data = simplexml_load_string($result);
$zpid=$data->response->results->result[0]->zpid;
echo $zpid;
?>
下面是我正在谈论的 XML:
<SearchResults:searchresults xmlns:xsi="http://www.w3.org/2001/XMLSchema- instance" xmlns:SearchResults="http://www.zillow.com/static/xsd/SearchResults.xsd" xsi:schemaLocation="http://www.zillow.com/static/xsd/SearchResults.xsd http://www.zillowstatic.com/vstatic/5b67875/static/xsd/SearchResults.xsd">
<request>...</request>
<message>...</message>
<response>
<results>
<result>
<zpid>2349353</zpid>
<links>...</links>
<address>
<street>5411 Lydia Ave</street>
<zipcode>64110</zipcode>
<city>Kansas City</city>
<state>MO</state>
<latitude>39.02831</latitude>
<longitude>-94.568747</longitude>
</address>
<zestimate>...</zestimate>
<localRealEstate>...</localRealEstate>
</result>
</results>
</response>
</SearchResults:searchresults>