json与map前台传值的区别

JSON 和 Map的相同点就是 key,value的方式存储的,json

而JSON精确的说键值只支持String(也能够存数值,可是数值存进去,取出来仍是String),Map键值均可以存储对象.   code

public static void main(String[] args) throws JSONException {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("opcode", "-1");
        jsonObject.put("msg", "11");
        jsonObject.put("data", "111111");
        System.out.println("json:"+jsonObject);
        
    
         HashMap<String, Object> map= new HashMap<String,Object>();
         map.put("opcode","2");
         map.put("msg", "22");
         map.put("data","222222");
         System.out.println("map:"+map);
    }对象

相关文章
相关标签/搜索