【发布时间】:2021-07-07 08:30:57
【问题描述】:
我从 api 获取 json :
{
"SuccessInfo": [
{
"key": "clothes,color",
"value": [
"pink",
"green",
"yellow",
"white",
"blue",
"black"
]
},
{
"key": "clothes,type",
"value": [
"female",
"male",
"child"
]
}
会计json,我设计了一个类:
public class Clothes{
public static class SuccessInfoBean{
private String key;
private List<String> value;
public SuccessInfoBean(String key , List<String> value){
this.key = key;
this.value = value;
}
}
}
在MainActivity中,我想知道如何解析“值”?
List<Clothes.SuccessInfoBean> infoBean = new ArrayList<>();
List<String> stringList = new ArrayList<>();
JSONObject jsonObject2 = new JSONObject(myJson2.toString());
JSONArray jsonArray = jsonObject2.getJSONArray("SuccessInfoBean");
for (int j =0; j < jsonArray.length(); j++){
JSONObject object2 = jsonArray.getJSONObject(j);
String key2 = object2.getString("key");
stringList.add(object2.getString("value"));
我的用户 infoBean.add(key,stringList) 会出错,
哪一部分错了?
【问题讨论】:
-
你应该看看Retrofit library
标签: android json android-recyclerview