Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSONArray to HashMap

Tags:

json

android

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?

like image 359
Fabian Avatar asked Dec 22 '22 20:12

Fabian


1 Answers

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.

like image 165
Gandalf Avatar answered Dec 24 '22 11:12

Gandalf