gpt4 book ai didi

android - 解析数组中的json数据数组

转载 作者:行者123 更新时间:2023-11-29 15:25:18 24 4
gpt4 key购买 nike

   {
"TABLE":[
{
"ROW":[
{
"COL":[
{
"DATA":"< OutBoundSMS PhoneId='3' PhoneNo='1111111111' MessageText='OutBound SMS Application Test' />"
}
]
}
]
}
]
}

如何解析这种格式的json数组?
解析时出现此错误:“无法转换为 json 对象”。

最佳答案

将当前 Json 字符串解析为:

JSONObject json=new JSONObject("Your Json String");
JSONArray jsonarray = json.getJSONArray("TABLE");

for(int i=0;i<jsonarray.length();i++){

JSONObject jsonnew=jsonarray.getJSONObject(i);
JSONArray jsonarrayROW = jsonnew.getJSONArray("ROW");

for(int j=0;j<jsonarrayROW.length();j++){
JSONObject jsonnewtwo=jsonarrayROW.getJSONObject(j);
JSONArray jsonarrayCOL = jsonnewtwo.getJSONArray("COL");

for(int k=0;k<jsonarrayCOL.length();k++){

JSONObject jsonnewthree=jsonarrayCOL.getJSONObject(k);

//get DATA here

String str_data=jsonnewthree.getString("DATA");
}
}
}

关于android - 解析数组中的json数据数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14000676/

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