How to iterate a JsonObject (gson)

前端 未结 5 1152
有刺的猬
有刺的猬 2021-02-19 08:50

I have a JsonObject e.g

JsonObject jsonObject = {\"keyInt\":2,\"keyString\":\"val1\",\"id\":\"0123456\"}

Every JsonObject contains

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-19 09:37

    Just make following changes...

    Map attributes = new HashMap();
    Set> entrySet = jsonObject.entrySet();
    for(Map.Entry entry : entrySet){
     attributes.put(entry.getKey(), jsonObject.get(entry.getKey()).getAsString());
    }
    

    "getAsString" will do the magic for u

提交回复
热议问题