亚洲精品国产精品乱码视色,下载应用成人电影AVapp,成人影院下载视频

      <track id="gfhue"><i id="gfhue"></i></track><input id="gfhue"></input>

      1. 更多精彩內(nèi)容,歡迎關(guān)注:

        視頻號
        視頻號

        抖音
        抖音

        快手
        快手

        微博
        微博

        當(dāng)前位置:首頁 科技百科 java fastjson

        java fastjson

        文檔

        java fastjson

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

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

        1、FastJson的介紹:

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

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

        2、FastJson的特點:

        1.FastJson數(shù)度快,無論序列化和反序列化,都是當(dāng)之無愧的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字符串-數(shù)組類型
        private?static?final?String??JSON_ARRAY_STR?=?"[{\"studentName\":\"lily\",\"studentAge\":12},{\"studentName\":\"lucy\",\"studentAge\":15}]";
        //復(fù)雜格式j(luò)son字符串
        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對象之間的轉(zhuǎn)換

        *?簡單JavaBean_obj到j(luò)son對象的轉(zhuǎn)換
        ?*/
        @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的轉(zhuǎn)換
        ?*/
        @Test
        public?void?testJSONObjectToJavaBean(){
        ????//已知簡單json對象
        ????JSONObject?jsonObject?=?JSONObject.parseObject(JSON_OBJ_STR);
        ????//第一種方式,使用TypeReference類,由于其構(gòu)造方法使用protected進行修飾,故創(chuàng)建其子類
        ????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之間的轉(zhuǎn)換

        /**
        ?*?JavaList到JsonArray的轉(zhuǎn)換
        ?*/
        @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的轉(zhuǎn)換
        ?*/
        @Test
        public?void?testJsonArrayToJavaList()?{
        ????//已知JsonArray
        ????JSONArray?jsonArray?=?JSONArray.parseArray(JSON_ARRAY_STR);
        ????//第一種方式,使用TypeReference類,由于其構(gòu)造方法使用protected進行修飾,故創(chuàng)建其子類
        ????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之間的轉(zhuǎn)換

        /**
        ?*?JavaList到JsonArray的轉(zhuǎn)換
        ?*/
        @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的轉(zhuǎn)換
        ?*/
        @Test
        public?void?testJsonArrayToJavaList()?{
        ????//已知JsonArray
        ????JSONArray?jsonArray?=?JSONArray.parseArray(JSON_ARRAY_STR);
        ????//第一種方式,使用TypeReference類,由于其構(gòu)造方法使用protected進行修飾,故創(chuàng)建其子類
        ????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、復(fù)雜JavaBean_obj與json對象之間的轉(zhuǎn)換/**

        *?復(fù)雜JavaBean_obj到j(luò)son對象的轉(zhuǎn)換
        ?*/
        @Test
        public?void?testComplexJavaBeanToJSONObject()?{
        ????//已知復(fù)雜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);
        }
        /**
        ?*?復(fù)雜json對象到JavaBean_obj的轉(zhuǎn)換
        ?*/
        @Test
        public?void?testComplexJSONObjectToJavaBean()?{
        ????//已知復(fù)雜json對象
        ????JSONObject?jsonObject?=?JSONObject.parseObject(COMPLEX_JSON_STR);
        ????//第一種方式,使用TypeReference類,由于其構(gòu)造方法使用protected進行修飾,故創(chuàng)建其子類
        ????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);
        }

        總結(jié)

        //?把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轉(zhuǎn)換為JSONObject或者JSONArray。
        ????????public?static?final?Object?toJSON(Object?javaObject);

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

        文檔

        java fastjson

        JSON(javaScript Object Notation)是一種輕量級的數(shù)據(jù)交換格式,主要采用鍵值對({"name": "json"})的方式來保存和表示數(shù)據(jù),JSON是JS對象的字符串表示法,它使用文本表示一個JS對象的信息,本質(zhì)上是一個字符串。
        推薦度:
        為你推薦
        資訊專欄
        熱門視頻
        相關(guān)推薦
        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循環(huán) java fork java ecc加密 java formatter java dict java development java fastdfs java dev java dependency java調(diào)用asmx接口 java delete java獲取絕對值 java調(diào)用c++ java調(diào)用c++接口 java delegate java decodeuri java decode java調(diào)python java decaf java讀取本地excel java讀取json java dataset java規(guī)則引擎 java dataframe
        Top