gpt4 book ai didi

java - 像这样的简单json。创建和解析

转载 作者:行者123 更新时间:2023-11-29 03:30:54 25 4
gpt4 key购买 nike

是否可以像这样创建和解析json

{
"time1": { "UserId": "Action"},
"time2": { "UserId": "Action"},
"time3": { "UserId": "Action"}
}

json-simple.jar
我想继续使用元素 "time": { "UserId": "Action"}

更新 json

有什么帮助吗?请

最佳答案

是的,可以用它来创建:

JSONObject obj=new JSONObject();
JSONObject timeObj = new JSONObject();
timeObj.put("UserId", "Action");
obj.put("time", timeObj);

并解析

Object obj=JSONValue.parse(value);
JSONObject object=(JSONObject)obj;
JSONObject timeObj = obj.get("time");
String action = timeObj.get("UserId");

但我不建议你用这样的格式创建JSON,JSONObject属性键必须是唯一的,我建议你使用JSONArray而不是JSONObject

希望对你有帮助

关于java - 像这样的简单json。创建和解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18338846/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com