我在我的网站上访问过这个json文件:
[{
"01:03:2016": "410",
"02:03:2016": "200",
"03:03:2016": "380"
}]
我想使用PHP将格式更改为类似的内容,其中日期和计数都是值:
[{
"date": "01:03:2016",
"count": "410"
},
{
"date": "02:03:2016",
"count": "200"
},
{
"date": "03:03:2016",
"count": "380"
}]
答案 0 :(得分:0)
PHP
$string = file_get_contents("data.json"); // your current json data
$json_a = json_decode($string, true);
$new_json = array();
foreach ($json_a as $key => $value) {
$new_json[] = array("date"=>$key,'count'=>$value);
}
echo json_encode($new_json); //output
data.json文件(您当前的数据)
[{
"01:03:2016": "410",
"02:03:2016": "200",
"03:03:2016": "380"
}]