zoukankan      html  css  js  c++  java
  • 如何修改JSONObject 的值

    问 题

    {

    "result": {
        "total": "3",
        "shops": [
            {
                "shopId": "8b615ce0",
                "shopName": "舒",
                "icon": 
            },
            {
                "shopId": "f6f83000a",
                "shopName": "二号",
                "icon": 
            },
        ]
    },
    "code": 0,
    "message": "OK",
    "text": "OK"

    }
    JSONObject 对象rt
    想要修改“shops” 对应的值怎么修改??

    解决方案

    这是fastjson的例子

    JSONObject json = JSON.parseObject("{val: 123}");
    System.out.println("======before=====");
    System.out.println("size: " + json.size());
    System.out.println("val:  " + json.get("val"));
    json.put("val", 234); // 直接put相同的key
    System.out.println("======after======");
    System.out.println("size: " + json.size());
    System.out.println("val:  " + json.get("val"));

    结果

    ======before=====
    size: 1
    val:  123
    ======after======
    size: 1
    val:  234
    
  • 相关阅读:
    P4374 [USACO18OPEN]Disruption P
    POJ
    Git
    SpringBoot集成RabbitMQ
    GIS类型文件剖析
    SpringBoot全局异常处理
    SpringCloud Feign异常处理
    SpringBoot注解
    Restful风格接口定义
    LOD技术的理解
  • 原文地址:https://www.cnblogs.com/yelanggu/p/13260551.html
Copyright © 2011-2022 走看看