1. 程式人生 > >fastjson解析巢狀泛型

fastjson解析巢狀泛型

/**
 * author zoush
 * CreateTime 2017-06-03 16:01
 * 直接上虛擬碼
 */
public class Outer<T> {

    public String filed3 ;
    public Inner inner ;
    public List<T> data;
}

class Inner{
    public String filed ;
    public int filed2;
}

/** 泛型類 */
class  Fx{
    public String filed4 ;
    public int 
filed5; }

String jsonStr = "{\"filed3\":\"111\"," +
                    "\"data\":[{\"filed4\":\"111\",\"filed5\":222},{\"filed4\":\"333\",\"filed5\":444},{\"filed4\":\"555\",\"filed5\":666}]," +
                   "\"inner\":{\"filed\":\"777\",\"filed2\":8888}}";
Outer<Fx> outer = JSON.parseObject
(jsonStr,new TypeReference<Outer<Fx>>(){});