android - 我想阅读此 JSON 行,但因为它以 JSONObject 和 JsonArray 开头
问题描述
我只需要从下面的答案中保存第一个Table:[]行,例如在 Android Studio 的表布局中显示(获取字符串)值。请提供任何其他方式从以下代码中获取此详细信息,我在 http 请求中给出
{
"Result": {
"resultsrow": [
{
"RowError": "",
"RowState": 2,
"Table": [
{
"refno": "09127178888",
"name": "S Santhosh kumar",
"address": "qwerty",
"mobile": 123456789,
},
{
"refno": "0912717999999",
"name": "ggg",
"address": "gggttr54",
"mobile": 2134567890,
}
],
"ItemArray": [
"091271788888",
"S Santhosh kumar",
"qwerty1",
1234567890,
],
"HasErrors": false
},
{
"RowError": "",
"RowState": 2,
"Table": [
{
"refno": "091271788888",
"name": "S Santhosh kumar",
"address": "qwerty",
"mobile": 1234567890,
},
{
"refno": "091271799999",
"name": "ggg",
"address": "gggttr54, ",
"mobile": 2134567890,
}
],
"ItemArray": [
"0912717999999",
"ggg",
"gggttr54, ",
2134567890,
],
"HasErrors": false
}
]
},
"Message": "",
"Success": true
}
解决方案
请使用这个,这对你有用
try {
JSONObject j= new JSONObject(YourJsonString);
JSONObject result= (JSONObject) j.get("Result");
JSONArray resultsrowArray=result.getJSONArray("resultsrow");
for (int i = 0; i < resultsrowArray.length(); i++) {
JSONObject arrayObject= resultsrowArray.getJSONObject(i);
String RowError=arrayObject.getString("RowError");
int RowState=arrayObject.getInt("RowState");
JSONArray ItemArray=arrayObject.getJSONArray("ItemArray");
for (int i1 = 0; i1 < ItemArray.length(); i1++) {
String item1= ItemArray.getString(i1);
}
}
} catch (JSONException e) {
e.printStackTrace();
}
推荐阅读
- java - Java URI 本地文件系统解决问题
- javascript - 有没有办法用 discord.js 在变量中找到某个字母
- python - 如何从 AWS Lambda Python 函数中检索 URL 查询字符串参数?
- r - 如何在一列中加1到0
- c++ - 哪些指针值是明确定义的计算?
- nfc - iOS 13 NFC 核心 - 读取 NDEF 标签(例如 ISO 14443 Type A JavaCard)
- reactjs - Webpack:如果存在带有编译错误或 ESLint 错误的 Jest 测试,则导致实时重新加载和构建失败
- java - 删除 RecyclerView Firebase 项目 Android Java
- c - 如何将数据存储在也是指针的结构成员中?
- c# - C# Cassandra UDT 映射配置更好的方法