新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
JSONObject中的字段如何使用fastjson賦值-創(chuàng)新互聯(lián)
這篇文章將為大家詳細(xì)講解有關(guān)JSONObject中的字段如何使用fastjson賦值,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。
JSONObject對同一個key重新put時,新值就會取代舊值,沒有set之類的方法
構(gòu)建json string時,所有的引號都要轉(zhuǎn)義
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); } }
當(dāng)前文章:JSONObject中的字段如何使用fastjson賦值-創(chuàng)新互聯(lián)
標(biāo)題路徑:http://www.dlmjj.cn/article/djoghi.html