JSONArray到HashMap中JSONArray、HashMap

2023-09-05 09:38:46 作者:學哙嶶笶.

我有一个JSONArray,我需要得到HashMap中的值,因为我需要填充流,像Twitter完成。 您建议怎么办?

解决方案

 的HashMap<字符串,字符串>对=新的HashMap<字符串,字符串>();
的for(int i = 0; I< myArray.length();我++){
   的JSONObject J = myArray.optJSONObject(ⅰ);
   迭代它= j.keys();
   而(it.hasNext()){
      字符串n = it.next();
      pairs.put(N,j.getString(N));
   }
}
 

类似的东西。

I've a JSONArray and I need to get the hashmap with the values, because I need to populate a stream, like twitter done. What you suggest to do?

解决方案 JSONArray和JSONObject的区别

HashMap<String, String> pairs = new HashMap<String, String>();
for (int i = 0; i < myArray.length(); i++) {
   JSONObject j = myArray.optJSONObject(i);
   Iterator it = j.keys();
   while (it.hasNext()) {
      String n = it.next();
      pairs.put(n, j.getString(n));
   }
}

Something like that.