我在正确解析 PHP 中的数组时遇到了挑战。这是数组的输出:
[{"address":"2801 Elliott Ave","category_ids":[347],"category_labels":[["Social","Food and
Dining","Restaurants"]],"country":"us","email":"kimd@thedussingroup.com","factual_id":"43cfe23
8-ae8e-469a-8592-a1edc8603051","fax":"(206) 448-
9252","latitude":47.615154,"locality":"Seattle","longitude":-122.353724,"name":"The Old
Spaghetti Factory","neighborhood":["Belltown","Downtown","Downtown
Seattle"],"postcode":"98121","region":"WA","tel":"(206) 441-
7724","website":"http:\/\/www.osf.com"}]
这是解析尝试...
$mark = array("[");
$mark2 = array("]");
$replacemark = array("");
$array = str_replace($mark, $replacemark, $array);
$array = str_replace($mark2, $replacemark, $array);
$array = stripslashes($array);
$obj = json_decode($array);
$address = $obj->{'address'};
$country = $obj->{'country'};
$factual_id = $obj->{'factual_id'};
$latitude = $obj->{'latitude'};
$locality = $obj->{'locality'};
$longitude = $obj->{'longitude'};
$name = $obj->{'name'};
$postcode = $obj->{'postcode'};
$region = $obj->{'region'};
$status = $obj->{'status'};
$tel = $obj->{'tel'};
任何想法为什么这些值没有返回任何东西?谢谢!