PHP解析JSON数据
刚子 发布于 阅读:148
<?php
$jsonString = '{"errcode":0,"errmsg":"ok"}';
// 将JSON字符串转换为PHP对象
$dataObject = json_decode($jsonString);
// 将JSON字符串转换为PHP关联数组
$dataArray = json_decode($jsonString, true);
// 使用数据
echo $dataObject->errcode;
echo $dataArray['errcode'];
遍历是这样
$provinces = json_decode($response, true);
foreach($provinces['data']['list'] as $value){
echo "{$value['title']}<br>";
echo "{$value['url']}<br>";
echo "{$value['v_url']}<br>";
echo "{$value['cover_watermark']}<br>";
}