作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
如何用php将json数据转成html?
$url="http://api.nytimes.com/svc/search/v1/article?format=json&query=usa&rank=newest&api-key=mykey"
当我在浏览器中输入 url 时,它返回 {"offset" : "0" , "results" : [{"body" : "A guide to cultural and recreational goings-on in and around the Hudson Valley. ...}]}
如何放置 json body
数据转换成html?我的意思是这样echo '<div class="body"></div>';
最佳答案
您首先需要获取文件。你应该为此使用 curl。在下面的示例中,我使用了 file_get_contents()
函数,您可能想要替换它。使用 json_decode()
为您解析 JSON。
$json = file_get_contents($url);
$data = json_decode($json);
echo $data->results[0]->body;
这将回应A guide to cultural...
。
关于php - 如何用php将json数据转成html?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4634407/
我是一名优秀的程序员,十分优秀!