使用 php 更新 JSON 数组对象
Updating a JSON array object with php
如何使用 php 动态更新以下 JSON 对象?
这是我的 json.
{
"1":
{
"value0":
{
"id":0,
"status":0,
"quantity":"110"
},
"value1":
{
"id":1,
"status":1,
"quantity":"120"
}
}
"2":
{
value0":
{
"id":0,
"status":0,
"quantity":"132"
},
"value1":
{
"id":1,
"status":1,
"quantity":"123"
},
}
}
我想将值 0 的状态从键 1 更改为 1。
我怎样才能做到这一点?
使用json_decode()和json_enocde()
$data = json_decode($data,true);
$data["1"]["value0"]["status"]=1;
$data = json_encode($data);
echo $data;
如何使用 php 动态更新以下 JSON 对象?
这是我的 json.
{
"1":
{
"value0":
{
"id":0,
"status":0,
"quantity":"110"
},
"value1":
{
"id":1,
"status":1,
"quantity":"120"
}
}
"2":
{
value0":
{
"id":0,
"status":0,
"quantity":"132"
},
"value1":
{
"id":1,
"status":1,
"quantity":"123"
},
}
}
我想将值 0 的状态从键 1 更改为 1。 我怎样才能做到这一点?
使用json_decode()和json_enocde()
$data = json_decode($data,true);
$data["1"]["value0"]["status"]=1;
$data = json_encode($data);
echo $data;