用php更新JSON数组对象 [英] Updating a JSON array object with php

查看:59
本文介绍了用php更新JSON数组对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用php动态更新以下JSON对象?

How can i update the following JSON object dynamically using php?

这是我的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.我该如何实现?

I want to change the status of value0 from key 1, to 1. How can I acheive this?

推荐答案

使用 json_decode() json_enocde()

$data = json_decode($data,true);  
$data["1"]["value0"]["status"]=1;   
$data = json_encode($data);
echo $data;

这篇关于用php更新JSON数组对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆