fastjson对JSONObject中的指定字段重新赋值
fastjson
FASTJSON 2.0.x has been released, faster and more secure, recommend you upgrade.
项目地址:https://gitcode.com/gh_mirrors/fastj/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);
}
}
GitHub 加速计划 / fastj / fastjson
25.69 K
6.51 K
下载
FASTJSON 2.0.x has been released, faster and more secure, recommend you upgrade.
最近提交(Master分支:3 个月前 )
c942c834 - 1 年前
5bc4709b - 1 年前
更多推荐
已为社区贡献3条内容
所有评论(0)