在PHP中定义的json中插入数据

时间:2014-02-02 11:08:10

标签: php json

我有以下JSON:

[{"Start":{}},{"Driving route":{}},{"Lunch-Rest Break":{}},{"Break":{}},{"Waiting":{}},{"End":{}}] 

如何插入“1/8/2014”和“1/9/2014”等数据作为键“开始”的值,以便JSON看起来像:

[{"Start":{"1/8/2014","1/9/2014"}},{"Driving route":{}},{"Lunch-Rest Break":{}},{"Break":{}},{"Waiting":{}},{"End":{}}] 

1 个答案:

答案 0 :(得分:0)

例如这样?

$json_string = '[{"Start":{}},{"Driving route":{}},{"Lunch-Rest Break":{}},{"Break":{}},{"Waiting":{}},{"End":{}}]'; 
$x = json_decode($json_string,true);
$x[0]['Start'] = array("1/8/2014","1/9/2014");
$return_json = json_encode($x);
print $return_json;