FastJson解析JSON/マッピングエンティティ
2860 ワード
fastjsonは優れた性能を持つJava言語で実現されたJSON解像器と生成器であり、アリババのエンジニアから開発されました。
主な特徴:
クイックFAST(Javaに基づく他のいかなる解像度と生成器よりも速く、Jacksonを含む)強力(普通のJDKクラスに対応して、任意のJava Bean Class、Collection、Map、Dateまたはenumを含む)ゼロ依存(他のクラスに依存していないJDKを除く)Github:https://github.com/alibaba/fastjson
JSON解析:
主な特徴:
クイックFAST(Javaに基づく他のいかなる解像度と生成器よりも速く、Jacksonを含む)強力(普通のJDKクラスに対応して、任意のJava Bean Class、Collection、Map、Dateまたはenumを含む)ゼロ依存(他のクラスに依存していないJDKを除く)Github:https://github.com/alibaba/fastjson
JSON解析:
public class FastJsonMain {
static String json = "{\"study\": 10,\"study_course_count\": 10, \"recieved_reg_form_count\": 0,\"unread_count\": 5,\"teach_course_count\": 8,\"avatar\": \"1316634098115-02-57\",\"user_id\": 201,\"nickname\": \"Asus \"}";
static String arrayAyy="[[14,\" \"],[154,\" \"],[72,\" \"],null,[50,\" \"],[15,\" \"],[13\" \"],null,[1,\" \"],null]";
/**
* Json :FastJson , json K, , ..
*/
private void Json2Eetity() {
// TODO Auto-generated method stub
Welcome welcome = JSON.parseObject(json, Welcome.class);
System.out.println(welcome.toString());
System.out.println(welcome.getNickname());
}
/**
* Json
*/
private void Eetity2Json() {
// TODO Auto-generated method stub
Welcome welcome = new Welcome(2, 3, 4, 5, "imagUrl", 11, "Mers");
String json = JSON.toJSONString(welcome, true);
System.out.println(" Json:" + json);
}
/**
* list json
*/
public void list2Json() {
List<Welcome> list = new ArrayList<Welcome>();
Welcome welcome1 = new Welcome(2, 3, 4, 5, "imagUrl", 11, "Mers");
Welcome welcome2 = new Welcome(22, 33, 44, 55, "imag", 65, "Kers");
Welcome welcome3 = new Welcome(64, 33, 34, 05, "imagUrl", 43, "Wers");
Welcome welcome4 = new Welcome(62, 75, 41, 25, "imagUrl", 109, "Oers");
list.add(welcome1);
list.add(welcome2);
list.add(welcome3);
list.add(welcome4);
String json = JSON.toJSONString(list, true);
System.out.println("ist json :" + json);
}
/**
* String JSONArray
* null
*/
private void String2JSONArray() {
// TODO Auto-generated method stub
JSONArray array=JSONArray.parseArray(arrayAyy);
System.out.println(array);
System.out.println(" : "+array.size());
Collection nuCon = new Vector();
nuCon.add(null);
array.removeAll(nuCon);
System.out.println(array);
System.out.println(" : "+array.size());
}
public static void main(String[] args) {
FastJsonMain main = new FastJsonMain();
main.Json2Eetity();
System.out.println(" ");
main.Eetity2Json();
System.out.println("");
main.list2Json();
System.out.println(" ");
main.String2JSONArray();
}
}
以上fastjson-1.1.34:FastJson(ソース+jar+dome)