用PHP调用API返回JSON值,怎么把JSON返回值调用到html呢?
用PHP调用API返回JSON值,怎么把JSON返回值调用到html呢?
日期:2017-12-16 17:13:54 人气:1
用json_decode()将json字符串转化成php数组,然后直接循环数组取出值即可。
<?php
$content= file_get_contents('获取json字符串的url');
$content = json_decode($content);//将json字符串转化成php数组
foreach ($content as $key ) {//循环数组
echo '' . $key['city'