gpt4 book ai didi

Android JSON对象解析,无法获取状态

转载 作者:行者123 更新时间:2023-11-30 03:28:14 27 4
gpt4 key购买 nike

{"Sam":{"status":"available","classkey":"dotnet"}}

如何解析这种类型的json?

try {
JSONObject jObj = new JSONObject(json);
if(jObj != null){
domtdl = jObj.getString(dom);
try {
JSONObject c = new JSONObject(domtdl);
if(c != null){
status = c.getString(TAG_STATUS);
System.out.println(status);
}
} catch (JSONException e) {
e.printStackTrace();
}
}

} catch (JSONException e) {
e.printStackTrace();
}

是否正确?我不知道如何从第二个 JSON 对象获取数据。请帮助我。

最佳答案

对于这个特定的 json 字符串 {"Sam":{"status":"available","classkey":"dotnet"}}

你需要做的

try {
JSONObject jObj = (new JSONObject(json)).getJSONObject("Sam");
String status = jObj.getString("status");
String classkey = jObj.getString("classkey");
} catch (JSONException e) {
e.printStackTrace();
}

关于Android JSON对象解析,无法获取状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17896129/

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