Putting HashMap in jsonobject

后端 未结 3 895
礼貌的吻别
礼貌的吻别 2021-01-21 03:30

i building a json object that consists of nameValue pairs defined in a Hashmap

the issue i am having is when i invoke:

jsonObject.put(hashmap);
         


        
3条回答
  •  无人及你
    2021-01-21 04:10

    Use JSON's putAll.

            Map myMap = new HashMap();
            JSONObject jsonObject = new JSONObject();
    
            jsonObject.putAll(myMap);
    

提交回复
热议问题