我有一根绳子 [{Label_0=Mobile, Phone_0=+212131231}]
,存储在 ArrayList
内 HashMap
,我需要分配给另一个 Arraylist
获取值但获取语法错误
List<HashMap<String, String>> phonesArr = new ArrayList<HashMap<String, String>>();
HashMap<String, String> phoneDict = new HashMap<String, String>();
phoneDict.put(String.format("Label_%d", locali1),PTYPE);
phoneDict.put(String.format("Phone_%d", locali1),phoneNumber);
phonesArr.add(phoneDict);
我之所以要将其存储在一个数组中,是因为一个联系人可以有多个电话号码。
ArrayList<HashMap<String, String>> _allPeoplesDictArr = new ArrayList<HashMap<String, String>>();
HashMap<String, String> personDict = new HashMap<String, String>();
personDict.put("PhoneNumbers", phonesArr.toString()) //// Value stored as array to string
// [{Label_0=Mobile, Phone_0=+212131231}]
_allPeoplesDictArr.add(personDict);
for (int j = 0; j < _allPeoplesDictArr.size(); j++) {
String localPhoneStr = _allPeoplesDictArr.get(j)
.get("PhoneNumbers");
Log.d("localPhoneStr", localPhoneStr); /// I dont want to retrieve it as string
List<HashMap<String, String>> localPhoneArr = _allPeoplesDictArr.get(j).get("PhoneNumbers"); //// I want to retrieve it as array but getting syntax error.
if (localPhoneArr.size() > 0) {
for (int k = 0; k < localPhoneArr.size(); k++) {
HashMap<String, String> userDict = new HashMap<String, String>();
userDict.put(
"label",
localPhoneArr.get(k).get(
String.format("Label_%d", k)));
userDict.put(
"value",
localPhoneArr.get(k).get(
String.format("Phone_%d", k)));
}
}
}
I am getting syntax error at grabing values that is now as a JSON `[{Label_0=Mobile, Phone_0=+212131231}]`
List<HashMap<String, String>> localPhoneArr = _allPeoplesDictArr.get(j).get("PhoneNumbers");
1条答案
按热度按时间jm2pwxwz1#
线路
List<HashMap<String, String>> localPhoneArr = _allPeoplesDictArr.get(j).get("PhoneNumbers");
是给你语法错误,因为它是一个String
. 如果你想做一个Array
除此之外,还必须解析json字符串。你可以在这里找到文档应该是这样的