我正在像这样的数组形式得到json响应
["Monday","Wednesday","Friday"]
,但并未将其保存为android中的数组,我将其存储在这样的字符串中
String daysOfInterest = map.get("daysOfinterest");
[{"careTypeId":"10","careTypeName":"Vacation Care","daysOfinterest":["Tuesday","Thursday","Saturday"],"childDaysOfInterestId":"424"},
{"careTypeId":"10","careTypeName":"Vacation Care","daysOfinterest":["Monday","Wednesday","Friday"],"childDaysOfInterestId":"425"}]
这是我的回应,我将daysofInterest存储在hashmap中...并开始使用hashmap
但我想以数组形式获取
最佳答案
您可以使用此将json数组转换为java数组
ArrayList<String> list = new ArrayList<String>();
JSONArray jsonArray = (JSONArray)jsonObject;
if (jsonArray != null) {
int len = jsonArray.length();
for (int i=0;i<len;i++){
list.add(jsonArray.get(i).toString());
}
}
String[] myArray = list.toArray(new String[list.size()]);
然后可以将数组元素传递到地图。更多信息在这里Convert Json Array to normal Java Array