http://www.studytrails.com/java/json/jackson-create-json.jsp
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.databind.ObjectMapper;
public class JackjsonCfg {
public static void main(String[] args) throws Exception {
ObjectMapper mapper = new ObjectMapper();
SimpleDateFormat outputFormat = new SimpleDateFormat("dd MMM yyyy");
mapper.setDateFormat(outputFormat);
// to enable standard indentation ("pretty-printing"):
System.out.println("----------------------格式化输出-------------------");
Map<String, Object> mapJson = new HashMap<String, Object>();
mapJson.put("nameLove", "zhangs");
mapJson.put("date", new Date(System.currentTimeMillis()));
String sjson = mapper.writeValueAsString(mapJson);
System.out.println(sjson);
}
}
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.databind.ObjectMapper;
public class JackjsonCfg {
public static void main(String[] args) throws Exception {
ObjectMapper mapper = new ObjectMapper();
SimpleDateFormat outputFormat = new SimpleDateFormat("dd MMM yyyy");
mapper.setDateFormat(outputFormat);
// to enable standard indentation ("pretty-printing"):
System.out.println("----------------------格式化输出-------------------");
Map<String, Object> mapJson = new HashMap<String, Object>();
mapJson.put("nameLove", "zhangs");
mapJson.put("date", new Date(System.currentTimeMillis()));
String sjson = mapper.writeValueAsString(mapJson);
System.out.println(sjson);
}
}