JSONArray到HashMap中 [英] JSONArray to HashMap

查看:359
本文介绍了JSONArray到HashMap中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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?

解决方案

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.

这篇关于JSONArray到HashMap中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆