原始json:
{
"code":0,
"data":{
[
{
"amount":0,
"auditTime":"",
"channelType":"",
"createTime":"2019-08-13 17:01:55",
"creditStatus":"",
"edit":true,
"fundsStatus":"",
"id":372,
"idNo":"",
"lendRequestId":0,
"mobile":"13289989000",
"name":"客户姓名",
"soinsStatus":"",
"state":0,
"stateText":"",
"viewStateText":0
}
]
},
"mask":"251eeedb-e214-47c6-aa0c-3eb6c7b67aa0",
"msg":"success",
"timestamp":1566089672
}
=============================================================================================================================================
1、将json字符串转化为json对象
//将json字符串转化为json对象
JSONObject json = JSONObject.parseObject(content);
输出
{
"msg":"success",
"code":0,
"data":{
[
{
"amount":0,
"soinsStatus":"",
"viewStateText":0,
"edit":true,
"mobile":"12324435555",
"channelType":"",
"creditStatus":"",
"fundsStatus":"",
"idNo":"",
"auditTime":"",
"createTime":"2019-08-13 17:01:55",
"stateText":"",
"name":"客户姓名",
"id":372,
"lendRequestId":0,
"state":0
}
]
},
"mask":"251eeedb-e214-47c6-aa0c-3eb6c7b67aa0",
"timestamp":1566089672
}
2、取出data部分
//取出data部分对象
JSONObject data = json.getJSONObject("data");
输出:
{
[
{
"amount":0,
"soinsStatus":"",
"viewStateText":0,
"edit":true,
"mobile":"13234444555",
"channelType":"",
"creditStatus":"",
"fundsStatus":"",
"idNo":"",
"auditTime":"",
"createTime":"2019-08-13 17:01:55",
"stateText":"",
"name":"客户姓名",
"id":372,
"lendRequestId":0,
"state":0
}
]
}
3、data中包含有数组,list中的内容带有中括号[],所以要转化为JSONArray类型的对象
//如果要取出amount的值
JSONArray jsonArray = data.getJSONArray("data").getJSONObject(0).getString("amount");
输出:
[
{
"amount":0,
"soinsStatus":"",
"viewStateText":0,
"edit":true,
"mobile":"13234444555",
"channelType":"",
"creditStatus":"",
"fundsStatus":"",
"idNo":"",
"auditTime":"",
"createTime":"2019-08-13 17:01:55",
"stateText":"",
"name":"客户姓名",
"id":372,
"lendRequestId":0,
"state":0
}
]
4、若为多个数组
jsonArray.getJSONObject(index)
//随机选取一个数组
JSONObject idInfo = jsonArray.getJSONObject(randomInteger(0,jsonArray.size()));
String id=idInfo.getString("id");
&spm=1001.2101.3001.5002&articleId=115733427&d=1&t=3&u=266a4b304f4d46f69e06276da2139e2d)
389

被折叠的 条评论
为什么被折叠?



