<th id="wu2k2"><s id="wu2k2"></s></th> <blockquote id="wu2k2"></blockquote>
  • <tr id="wu2k2"></tr>
  • <samp id="wu2k2"><tbody id="wu2k2"></tbody></samp><samp id="wu2k2"><tbody id="wu2k2"></tbody></samp>
  • 更多精彩內容,歡迎關注:

    視頻號
    視頻號

    抖音
    抖音

    快手
    快手

    微博
    微博

    java fastjson

    文檔

    java fastjson

    JSON(javaScript Object Notation)是一種輕量級的數據交換格式,主要采用鍵值對({"name": "json"})的方式來保存和表示數據,JSON是JS對象的字符串表示法,它使用文本表示一個JS對象的信息,本質上是一個字符串。
    推薦度:
    導讀JSON(javaScript Object Notation)是一種輕量級的數據交換格式,主要采用鍵值對({"name": "json"})的方式來保存和表示數據,JSON是JS對象的字符串表示法,它使用文本表示一個JS對象的信息,本質上是一個字符串。

    很多朋友都想知道java fastjson是什么?下面就一起來了解一下吧~

    1、FastJson的介紹:

      JSON(javaScript Object Notation)是一種輕量級的數據交換格式。主要采用鍵值對({"name": "json"})的方式來保存和表示數據。JSON是JS對象的字符串表示法,它使用文本表示一個JS對象的信息,本質上是一個字符串。

      JSON的處理器有很多,這里我介紹一下FastJson,FastJson是阿里的開源JSON解析庫,可以解析JSON格式的字符串,支持將Java Bean序列化為JSON字符串,也可以從JSON字符串反序列化到JavaBean。是一個極其優秀的Json框架,Github地址:?FastJson

    2、FastJson的特點:

    1.FastJson數度快,無論序列化和反序列化,都是當之無愧的fast?2.功能強大(支持普通JDK類包括任意Java Bean Class、Collection、Map、Date或enum)?3.零依賴(沒有依賴其它任何類庫)

    3、FastJson的用法:

    首先定義三個json格式的字符串

    //json字符串-簡單對象型
    private?static?final?String??JSON_OBJ_STR?=?"{\"studentName\":\"lily\",\"studentAge\":12}";
    //json字符串-數組類型
    private?static?final?String??JSON_ARRAY_STR?=?"[{\"studentName\":\"lily\",\"studentAge\":12},{\"studentName\":\"lucy\",\"studentAge\":15}]";
    //復雜格式json字符串
    private?static?final?String??COMPLEX_JSON_STR?=?"{\"teacherName\":\"crystall\",\"teacherAge\":27,\"course\":{\"courseName\":\"english\",\"code\":1270},\"students\":[{\"studentName\":\"lily\",\"studentAge\":12},{\"studentName\":\"lucy\",\"studentAge\":15}]}";

    4、簡單javaBean與json對象之間的轉換

    *?簡單JavaBean_obj到json對象的轉換
    ?*/
    @Test
    public?void?testJavaBeanToJSONObject(){
    ????//已知簡單JavaBean_obj
    ????Student?student?=?new?Student("lily",?12);
    ????//方式一
    ????String?jsonString?=?JSONObject.toJSONString(student);
    ????JSONObject?jsonObject?=?JSONObject.parseObject(jsonString);
    ????System.out.println(jsonObject);
    ????//方式二
    ????JSONObject?jsonObject1?=?(JSONObject)?JSONObject.toJSON(student);
    ????System.out.println(jsonObject1);
    }
    /**
    ?*?簡單json對象到JavaBean_obj的轉換
    ?*/
    @Test
    public?void?testJSONObjectToJavaBean(){
    ????//已知簡單json對象
    ????JSONObject?jsonObject?=?JSONObject.parseObject(JSON_OBJ_STR);
    ????//第一種方式,使用TypeReference類,由于其構造方法使用protected進行修飾,故創建其子類
    ????Student?student?=?JSONObject.parseObject(jsonObject.toJSONString(),?new?TypeReference()?{});
    ????System.out.println(student);
    ????//第二種方式,使用Gson的思想
    ????Student?student1?=?JSONObject.parseObject(jsonObject.toJSONString(),?Student.class);
    ????System.out.println(student1);
    }

    5、JavaList與JsonArray之間的轉換

    /**
    ?*?JavaList到JsonArray的轉換
    ?*/
    @Test
    public?void?testJavaListToJsonArray()?{
    ????//已知JavaList
    ????Student?student?=?new?Student("lily",?12);
    ????Student?studenttwo?=?new?Student("lucy",?15);
    ????List?students?=?new?ArrayList();
    ????students.add(student);
    ????students.add(studenttwo);
    ????//方式一
    ????String?jsonString?=?JSONArray.toJSONString(students);
    ????JSONArray?jsonArray?=?JSONArray.parseArray(jsonString);
    ????System.out.println(jsonArray);
    ????//方式二
    ????JSONArray?jsonArray1?=?(JSONArray)?JSONArray.toJSON(students);
    ????System.out.println(jsonArray1);
    }
    /**
    ?*?JsonArray到JavaList的轉換
    ?*/
    @Test
    public?void?testJsonArrayToJavaList()?{
    ????//已知JsonArray
    ????JSONArray?jsonArray?=?JSONArray.parseArray(JSON_ARRAY_STR);
    ????//第一種方式,使用TypeReference類,由于其構造方法使用protected進行修飾,故創建其子類
    ????ArrayList?students?=?JSONArray.parseObject(jsonArray.toJSONString(),
    ????????????new?TypeReference>()?{});
    ????System.out.println(students);
    ????//第二種方式,使用Gson的思想
    ????List?students1?=?JSONArray.parseArray(jsonArray.toJSONString(),?Student.class);
    ????System.out.println(students1);
    }

    6、JavaList與JsonArray之間的轉換

    /**
    ?*?JavaList到JsonArray的轉換
    ?*/
    @Test
    public?void?testJavaListToJsonArray()?{
    ????//已知JavaList
    ????Student?student?=?new?Student("lily",?12);
    ????Student?studenttwo?=?new?Student("lucy",?15);
    ????List?students?=?new?ArrayList();
    ????students.add(student);
    ????students.add(studenttwo);
    ????//方式一
    ????String?jsonString?=?JSONArray.toJSONString(students);
    ????JSONArray?jsonArray?=?JSONArray.parseArray(jsonString);
    ????System.out.println(jsonArray);
    ????//方式二
    ????JSONArray?jsonArray1?=?(JSONArray)?JSONArray.toJSON(students);
    ????System.out.println(jsonArray1);
    }
    /**
    ?*?JsonArray到JavaList的轉換
    ?*/
    @Test
    public?void?testJsonArrayToJavaList()?{
    ????//已知JsonArray
    ????JSONArray?jsonArray?=?JSONArray.parseArray(JSON_ARRAY_STR);
    ????//第一種方式,使用TypeReference類,由于其構造方法使用protected進行修飾,故創建其子類
    ????ArrayList?students?=?JSONArray.parseObject(jsonArray.toJSONString(),
    ????????????new?TypeReference>()?{});
    ????System.out.println(students);
    ????//第二種方式,使用Gson的思想
    ????List?students1?=?JSONArray.parseArray(jsonArray.toJSONString(),?Student.class);
    ????System.out.println(students1);
    }

    7、復雜JavaBean_obj與json對象之間的轉換/**

    *?復雜JavaBean_obj到json對象的轉換
    ?*/
    @Test
    public?void?testComplexJavaBeanToJSONObject()?{
    ????//已知復雜JavaBean_obj
    ????Student?student?=?new?Student("lily",?12);
    ????Student?studenttwo?=?new?Student("lucy",?15);
    ????List?students?=?new?ArrayList();
    ????students.add(student);
    ????students.add(studenttwo);
    ????Course?course?=?new?Course("english",?1270);
    ????Teacher?teacher?=?new?Teacher("crystall",?27,?course,?students);
    ????//方式一
    ????String?jsonString?=?JSONObject.toJSONString(teacher);
    ????JSONObject?jsonObject?=?JSONObject.parseObject(jsonString);
    ????System.out.println(jsonObject);
    ????//方式二
    ????JSONObject?jsonObject1?=?(JSONObject)?JSONObject.toJSON(teacher);
    ????System.out.println(jsonObject1);
    }
    /**
    ?*?復雜json對象到JavaBean_obj的轉換
    ?*/
    @Test
    public?void?testComplexJSONObjectToJavaBean()?{
    ????//已知復雜json對象
    ????JSONObject?jsonObject?=?JSONObject.parseObject(COMPLEX_JSON_STR);
    ????//第一種方式,使用TypeReference類,由于其構造方法使用protected進行修飾,故創建其子類
    ????Teacher?teacher?=?JSONObject.parseObject(jsonObject.toJSONString(),?new?TypeReference()?{});
    ????System.out.println(teacher);
    ????//第二種方式,使用Gson的思想
    ????Teacher?teacher1?=?JSONObject.parseObject(jsonObject.toJSONString(),?Teacher.class);
    ????System.out.println(teacher1);
    }

    總結

    //?把JSON文本parse為JSONObject或者JSONArray
    ????????public?static?final?Object?parse(String?text);??
    ????????//?把JSON文本parse成JSONObject
    ????????public?static?final?JSONObject?parseObject(String?text);
    ????????//?把JSON文本parse為JavaBean
    ????????public?static?final??T?parseObject(String?text,?Class?clazz);?
    ????????//?把JSON文本parse成JSONArray
    ????????public?static?final?JSONArray?parseArray(String?text);?
    ????????//把JSON文本parse成JavaBean集合
    ????????public?static?final??List?parseArray(String?text,?Class?clazz);?????
    ????????//?將JavaBean序列化為JSON文本
    ????????public?static?final?String?toJSONString(Object?object);???????
    ????????//?將JavaBean序列化為帶格式的JSON文本
    ????????public?static?final?String?toJSONString(Object?object,?boolean?prettyFormat);?
    ????????//將JavaBean轉換為JSONObject或者JSONArray。
    ????????public?static?final?Object?toJSON(Object?javaObject);

    以上就是小編今天的分享,希望可以幫到大家。

    文檔

    java fastjson

    JSON(javaScript Object Notation)是一種輕量級的數據交換格式,主要采用鍵值對({"name": "json"})的方式來保存和表示數據,JSON是JS對象的字符串表示法,它使用文本表示一個JS對象的信息,本質上是一個字符串。
    推薦度:
    為你推薦
    資訊專欄
    熱門視頻
    相關推薦
    java feign java divide java field java field獲取值 java dockerfile java file.exists() java fileinputstream java findfirst java flatmap java dowhile java flink java drools java dto java dynamic java flume java ear java foreach循環 java fork java ecc加密 java formatter java dict java development java fastdfs java dev java dependency java調用asmx接口 java delete java獲取絕對值 java調用c++ java調用c++接口 java delegate java decodeuri java decode java調python java decaf java讀取本地excel java讀取json java dataset java規則引擎 java dataframe
    Top 国产在线精品二区赵丽颖| 亚洲精品电影在线| 日韩在线视精品在亚洲| 久久婷婷国产综合精品| 久久亚洲av无码精品浪潮 | 亚洲精品**中文毛片| 国产亚洲精品免费视频播放| 在线观看亚洲精品专区| 国产精品久久久久久搜索 | 国产69精品久久久久777| 国产办公室秘书无码精品99| 亚洲精品第一国产综合精品99| 亚洲综合精品伊人久久| 精品无码一区在线观看| 久久国产精品2020盗摄| 国产亚洲精品成人AA片新蒲金| www.亚洲精品.com| 国产精品久久久久久久伊一| 国产精品无码一区二区在线| 日韩精品一区二区三区中文精品| 亚洲人成亚洲精品| 久久精品视频16| 青青青国产精品国产精品久久久久| 精品精品国产国产| 一本色道久久88综合亚洲精品高清| 无码A级毛片日韩精品| 国产精品美女午夜爽爽爽免费| 51视频国产精品一区二区| 91久久精品午夜一区二区 | 成人综合久久精品色婷婷| 日本亚洲精品色婷婷在线影院| 99久久国产综合精品1尤物| 久久夜色精品国产网站| 日韩精品无码一区二区三区免费 | 国产成人精品影院狼色在线| 香蕉久久国产精品免| 国产精品无码一区二区三区不卡| 国内精品久久久久影院亚洲| 国产精品自在自线视频 | 国产成人精品一区二三区在线观看 | 香蕉在线精品一区二区|