[英]Parsing a JSON Array into a Java array returns the last element as the second index
So I'm working with a local JSON file, and when I try to parse it into a Java data structure everything goes fine except as the title suggests, the last element of the JSON array is returned as the second element of the Java array 因此,我正在使用本地JSON文件,当我尝试将其解析为Java数据结构时,一切正常,除了标题所示,JSON数组的最后一个元素作为Java数组的第二个元素返回
"text": [
{
"0": "text"
}, {
"3": "text"
}, {
"5": "text:"
}, {
"6": "text:"
}, {
"7": "text:"
}, {
"8": "text"
}, {
"9": "text:"
}, {
"9": "text"
}, {
"10": "text:"
}, {
"11": ""
}
]
for(int j = 0; j < arr.length(); j++) {
String index = content.getJSONObject(j).names().get(0).toString();
String ToCVal = content.getJSONObject(j).getString(index);
temp_hashmap.put(index, ToCVal);
那不是JsonObject的问题,它是HashMap的问题,您必须使用LinkedHashMap来保存订单
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.