package com.jdk.json;
import com.alibaba.fastjson.JSON;
import com.jkd.entity.School;
public class Fastjson_Json
{
public static String jsonString = "{\n" +
" \"name\": \"teacher\",\n" +
" \"computer\": {\n" +
" \"cpu\": \"intel7\",\n" +
" \"disk\": \"512G\"\n" +
" },\n" +
" \"students\": [\n" +
" {\n" +
" \"name\": \"张三\",\n" +
" \"age\": 18,\n" +
" \"sex\": \"男\"\n" +
" },\n" +
" {\n" +
" \"name\": \"李四\",\n" +
" \"age\": 19,\n" +
" \"sex\": \"男\"\n" +
" }\n" +
" ]\n" +
"}\n";
public static void main(String[] args)
{
//Json转换为java对象
School school = JSON.parseObject(jsonString, School.class);
System.out.println(school);
//java对象转换为Json
String s = JSON.toJSONString(school);
System.out.println(s);
//注意:fastjson要求JSON串中属性名一定要是小写
}
}