List> to org.json.JSONObject?

后端 未结 8 2020
借酒劲吻你
借酒劲吻你 2020-12-14 20:12
List> list = new ArrayList>();
Map map = new HashMap();

         


        
8条回答
  •  时光取名叫无心
    2020-12-14 20:53

    List> list = new ArrayList>();
    Map map = new HashMap();
    
    map.put("abc", "123456");
    map.put("def", "hmm");
    list.add(map);
    // it's wrong JSONObject json = new JSONObject(list);
    // if u use list to add data u must be use JSONArray
    
    JSONArray json = JSONArray.fromObject(list);
    try {
        System.err.println(json.toString(2));
    } catch (JSONException e) {
        e.printStackTrace();
    }
    

提交回复
热议问题