我有来自api的json响应,我希望在PHP的页面中显示。我想知道该怎么做。我的json响应看起来像这样:
stdClass Object
(
[resultsFound] => 10
[resultsStart] => 0
[resultsShown] => 10
[delivery] => 9
[dineOut] => 9
[nightlife] => 0
[chillout] => 0
[takeaway] => 10
[all] => 10
[results] => Array
(
[0] => stdClass Object
(
[result] => stdClass Object
(
[id] => 310160
[name] => Andhra Biryani House
[address] => Shop 144, The Sapphire Mall, Opposite Orchid Petals, Sector 49, Near Sohna Road, Gurgaon
[locality] => Sohna Road
[hasOnlineDelivery] => 1
[onlineDeliveryLink] => https://www.zomato.com/ncr/andhra-biryani-house-sohna-road-gurgaon/order
[phone] => +91 9650508883
[city] => Gurgaon
[cuisines] => Biryani, Hyderabadi, Andhra
[distance_actual] => 0
[distance_friendly] => about 0 meters
[rating_aggregate] => 3.7
[votes] => 258
[rating_color] => 5BA829
[rating_text] => Very Good
[user_review_count] => 171
[rating_editor_overall] => 0
[cost_for_two] => 700
[has_discount] => 0
[has_citibank_discount] => 0
[has_emirates_discount] => 0
[latitude] => 28.4117236642
[longitude] => 77.0484169945
[has_menu] => 1
[has_bar] => 0
[is_pure_veg] => 0
[accepts_credit_card] => 0
[has_dine_in] => 1
[has_delivery] => 1
[has_coordinates] => 1
[image_470_310] =>
[image_310_310] =>
[image_310_150] =>
[image_150_150] =>
)
)
)
我需要一些关于在PHP页面中显示这些数据的建议。
答案 0 :(得分:0)
PHP通过HTTP打印到发送请求的客户端。通常客户端是一个浏览器,可以读取HTML,因此我假设您要在HTML页面中显示您的内容。个人最喜欢的是使用PHP的模板样式来准备页面,该页面被发送到客户端。你应该这样做:
<html>
<head>
<!--something-->
</head>
<body>
<!-- more something -->
<?php echo $myObject->locality;?>
<!-- and so on -->
</body>
</html>