新网创想网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

JSONObject中的字段如何使用fastjson赋值-创新互联

这篇文章将为大家详细讲解有关JSONObject中的字段如何使用fastjson赋值,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

创新互联公司专注于网站建设,为客户提供成都网站建设、做网站、网页设计开发服务,多年建网站服务经验,各类网站都可以开发,高端网站设计,公司官网,公司展示网站,网站设计,建网站费用,建网站多少钱,价格优惠,收费合理。

JSONObject对同一个key重新put时,新值就会取代旧值,没有set之类的方法

构建json string时,所有的引号都要转义

package xx;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
 
// 对JSONObject中的指定字段重新赋值
public class testJsonReplace {
 
  public static void main(String[] args) {
 
		String query_jsonstr = "{\"timezone\":\"GMT+0\",\"action\":\"front_BRAND\",\"format\":\"true\",\"lan\":\"en_us\",\"column\":[\"day\",\"impressions\",\"clicks\",\"ctr\",\"brand_estimated_ecpm\",\"pay_out\"],\"dimension\":[\"day\"],\"filter\":{\"posid\":{\"op\":\"in\",\"value\":\"2454105\"}},\"start\":1528761600000,\"end\":1529452800000}";
		JSONObject query = JSON.parseObject(query_jsonstr);
 
		if (query.getJSONObject("filter") != null) {
			JSONObject posJson = new JSONObject();
			posJson.put("op", "in");
			posJson.put("value", "2454117");
			query.getJSONObject("filter").put("posid", posJson);
		}
    String posid = query.getJSONObject("filter").getJSONObject("posid").getString("value");
		String newJsonStr = query.toJSONString();
		System.out.println(newJsonStr);
  }
}

网页题目:JSONObject中的字段如何使用fastjson赋值-创新互联
新闻来源:http://www.wjwzjz.com/article/djoghi.html
在线咨询
服务热线
服务热线:028-86922220
TOP