gpt4 book ai didi

java - Android - 在 JsonArray 上循环?

转载 作者:行者123 更新时间:2023-12-05 00:12:49 25 4
gpt4 key购买 nike

我如何在这个 JSON 上循环:

[{
"X": "54.6000621",
"Y": "45.8360411",
"Dates": [{
"Date": "2000\/04\/26",
"Time": "12:13:45"
}, {
"Date": "2000\/04\/26",
"Time": "13:13:45"
}, {
"Date": "2000\/04\/26",
"Time": "14:13:12"
}, {
"Date": "2000\/04\/26",
"Time": "15:13:10"
}, {
"Date": "2000\/04\/26",
"Time": "16:13:48"
}],
"Count": 5,
"X": "98.6254621",
"Y": "99.8360411",
"Dates": [{
"Date": "2012\/04\/26",
"Time": "12:13:45"
}, {
"Date": "2012\/04\/26",
"Time": "13:13:45"
}, {
"Date": "2012\/04\/26",
"Time": "14:13:12"
}, {
"Date": "2012\/04\/26",
"Time": "15:13:10"
}, {
"Date": "2012\/04\/26",
"Time": "16:13:48"
}, {
"Date": "2012\/04\/26",
"Time": "15:13:10"
}, {
"Date": "2012\/04\/26",
"Time": "15:13:10"
}],
"Count": 7,
"X": "58.4582621",
"Y": "85.8360411",
"Dates": [],
"Count": 0
}]

最佳答案

你的回复应该是这样的看看回复是否像我的回答

[{
"X": "54.6000621",
"Y": "45.8360411",
"Dates": [{
"Date": "2000\/04\/26",
"Time": "12:13:45"
}, {
"Date": "2000\/04\/26",
"Time": "13:13:45"
}, {
"Date": "2000\/04\/26",
"Time": "14:13:12"
}, {
"Date": "2000\/04\/26",
"Time": "15:13:10"
}, {
"Date": "2000\/04\/26",
"Time": "16:13:48"
}],
"Count": 5
},
{
"X": "98.6254621",
"Y": "99.8360411",
"Dates": [{
"Date": "2012\/04\/26",
"Time": "12:13:45"
}, {
"Date": "2012\/04\/26",
"Time": "13:13:45"
}, {
"Date": "2012\/04\/26",
"Time": "14:13:12"
}, {
"Date": "2012\/04\/26",
"Time": "15:13:10"
}, {
"Date": "2012\/04\/26",
"Time": "16:13:48"
}, {
"Date": "2012\/04\/26",
"Time": "15:13:10"
}, {
"Date": "2012\/04\/26",
"Time": "15:13:10"
}],
"Count": 7
},
{
"X": "58.4582621",
"Y": "85.8360411",
"Dates": [],
"Count": 0

}]

取值代码

     try {
JSONArray jsonArray=new JSONArray(response);
for (int i=0;i<jsonArray.length();i++)
{
JSONObject jsonObject=jsonArray.getJSONObject(i);

String X=jsonObject.getString("X");
String Y=jsonObject.getString("Y");
String Count=jsonObject.getString("Count");

JSONArray jsonArraydates=jsonObject.getJSONArray("Dates");

for (int j=0;j<jsonArraydates.length();j++)
{
JSONObject jsonObjectDates=jsonArraydates.getJSONObject(j);


String Date=jsonObjectDates.getString("Date");
String Time=jsonObjectDates.getString("Time");


}

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

关于java - Android - 在 JsonArray 上循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38735878/

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