歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux編程 >> Linux編程

Java後台JOSN轉換為Stirng

Java後台JOSN轉換為Stirng

jackson-mapper-asl-1.6.4.jar

import org.codehaus.jackson.map.ObjectMapper;

public static String convertObjectToJsonString(Object data){
return convertObjectToJsonString(null,data);
}
public static String convertObjectToJsonString(ObjectMapper mapper,Object data){
String json = "";
if(data==null) return json;
try {
if(mapper==null) mapper = new ObjectMapper();
json = mapper.writeValueAsString(data);
} catch (Exception e) {
log.error("convertObjectToJsonString", e);
}
return json;
}

Copyright © Linux教程網 All Rights Reserved