JSON

java Json 技术记录(4)

字号+ 作者:H5之家 来源:H5之家 2017-12-13 17:11 我要评论( )

package com.jxufe.study.jsonstudy.test; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.serializer.SerializerFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.goog

package com.jxufe.study.jsonstudy.test; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.serializer.SerializerFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import net.sf.json.JSONObject; import org.junit.Test; import java.io.IOException; import java.util.Date; /** * @author hong.zheng * @Description * @date 2017-12-08-10:31 * DateCompare { @Test public void jsonLibDate() { JSONObject jsonObject = JSONObject.fromObject(new Date()); System.out.println(jsonObject.toString()); //输出 {"date":8,"day":5,"hours":11,"minutes":7,"month":11,"seconds":2,"time":1512702422553,"timezoneOffset":-480,"year":117} } @Test public void fastJsonDate() { System.out.println(JSON.toJSON(new Date())); //输出 Fri Dec 08 11:07:14 CST 2017 JSON.DEFFAULT_DATE_FORMAT = "yyyy-MM-dd"; String jsonDate = JSON.toJSONString(new Date(), SerializerFeature.WriteDateUseDateFormat); System.out.println(jsonDate); //"2017-12-08" } @Test public void GsonDate() { Gson gson = new Gson(); System.out.println(gson.toJson(new Date())); //输出 "Dec 8, 2017 11:07:34 AM" gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create(); System.out.println(gson.toJson(new Date())); //输出 "2017-12-08" } @Test public void jacksonDate() throws IOException { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.writeValue(System.out,new Date()); //输出 1512702466576 } }

JsonLib 和 Jackson 

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • ASP.NET Core教程【一】关于Razor Page的知识

    ASP.NET Core教程【一】关于Razor Page的知识

    2017-11-30 18:05

  • python学习之路(二)

    python学习之路(二)

    2017-11-24 11:25

  • sqlserverToXML

    sqlserverToXML

    2017-11-10 17:05

  • shelve模块

    shelve模块

    2017-11-06 13:06

网友点评