How can I convert JSON to a HashMap using Gson?

前端 未结 16 2383
臣服心动
臣服心动 2020-11-22 05:14

I\'m requesting data from a server which returns data in the JSON format. Casting a HashMap into JSON when making the request wasn\'t hard at all but the other way seems to

16条回答
  •  旧时难觅i
    2020-11-22 05:52

     HashMap jsonToMap(String JsonDetectionString) throws JSONException {
    
        HashMap map = new HashMap();
        Gson gson = new Gson();
    
        map = (HashMap) gson.fromJson(JsonDetectionString, map.getClass());
    
        return map;
    
    }
    

提交回复
热议问题