我在哈希图中有一个哈希图,例如
List<Map> mapList = new ArrayList<Map>();
for (int i = 0; i < 2; i++) {
Map iMap = new HashMap();
iMap.put("Comment", "");
iMap.put("Start", "0");
iMap.put("Max", "0");
iMap.put("Min", "0");
iMap.put("Price", "5000.00");
iMap.put("DetailsID", "51");
mapList.add(iMap);
}
Map mMap = new HashMap();
mMap.put("ID", "27");
mMap.put("ParticipantID", "2");
mMap.put("ItemDetails", mapList);
我想迭代这张地图并为此放入 JSONObject
try {
JSONObject object = new JSONObject();
Iterator iterator = mMap.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry mEntry = (Map.Entry) iterator.next();
String key = mEntry.getKey().toString();
String value = mEntry.getValue().toString();
object.put(key, value);
}
Log.v(TAG, "Object : " + object);
回应就像
Object : {"ItemDetails":"[{Price=5000.00, Comment=, DetailsID=51, Min=0, Max=0, StartViolation=0}, {Price=5000.00, Comment=, DetailsID=51, Min=0, Max=0, StartViolation=0}]","ID":"27","ParticipantID":"2"}
hashmap 的内部列表没有迭代