Json类型转换代码

  • Post author:
  • Post category:其他


JSONObject的依赖


<dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.41</version> </dependency>

   //对象转json	  
	  String jsonString= JSONObject.toJSONString(putSampleParam);
  //String转json
	     String jsonString ="{\"name\":\"zss\",\"password\":\"zss112\",\"email\":\"221@qq.com\"}";  
         JSONObject json = JSONObject.fromObject(jsonString); 


//map转json
  Map<String, Object> map = new HashMap<String, Object>();
        map.put("a", "a");
        map.put("b", "b");
        JSONObject json = new JSONObject(map);
        
 //map转String
  Map<String, Object> map = new HashMap<>();
        map.put("a", "a");
        String s = JSONObject.toJSONString(map);



版权声明:本文为qq_44239079原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。