android解析HashMap格式的json

2021-09-12 01:32:09 字數 960 閱讀 1860

這種格式的json以前遇到的比較少,所以索性寫篇部落格記錄下是如何解析這種格式的json

因為是hashmap格式,檢視資料型別,所以可以直接定義乙個hashmap,mapassitnummap = new hashmap(), 用來承載hashmap的json,接下來需要遍歷hashmap, 因為很簡單,直接展示解析的**

string code = response.optstring("code");

if("1".equals(code))

}複製**

這種是最簡單的hashmap格式的json,現在來看一下有列表的hashmap格式的json

這種格式的json的hashmap的key對應的value是乙個列表,列表中是乙個實體,所以必須先建立乙個實體hashbean,set和get方法就不浪費篇幅了

public static class hashbean

複製**

後面建立乙個hashmap用來承載json,maphashmap = new hashmap<>();

然後iterator iterator = data.keys(), while (iterator.hasnext())進行遍歷,因為實體的是乙個list,所以建立乙個list hashlist = new arraylist<>(),去裝載遍歷的資料,詳情看**

string code = response.optstring("code");

if("1".equals(code))

}hashbean.sethashbean(hashlist);

}hashmap.put(key,hashbean);

}複製**

以上便是hashmap這種格式的json解析方法,記錄下來,以免後面忘掉了,大寫的尷尬。。。。。

ConcurrentMap和HashMap的區別

類 hashset 所有已實現的介面 serializable,cloneable,iterable,collection,set 此類實現 set 介面,由雜湊表 實際上是乙個 hashmap 例項 支援。它不保證 set 的迭代順序 特別是它不保證該順序恆久不變。此類允許使用 null 元素。此...

ConcurrentMap和HashMap的區別

類 hashset 所有已實現的介面 serializable,cloneable,iterable,collection,set 此類實現 set 介面,由雜湊表 實際上是乙個 hashmap 例項 支援。它不保證 set 的迭代順序 特別是它不保證該順序恆久不變。此類允許使用 null 元素。此...

hashma的put 方法總結

hashmap put 方法流程圖 hashmap的put方法流程總結 1 put key,value 中直接呼叫了內部的putval方法,並且先對key進行了hash操作 2 putval方法中,先檢查hashmap資料結構中的索引陣列表是否位空,如果是的話則進行一次resize操作 3 以has...