一、fastJSON 包
dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.33</version>
</dependency>
二、轉(zhuǎn)普通對象
自定義對象A
A aa = JSONObject.parseObject("字符串", A.class);
三、轉(zhuǎn)帶泛型對象文章來源:http://www.zghlxwxcb.cn/news/detail-835665.html
包括一層泛型、多層泛型文章來源地址http://www.zghlxwxcb.cn/news/detail-835665.html
// 一層泛型
A<B> orderData = JSON.parseObject("json字符串",new TypeReference<A<B>>(){});
// 多層泛型
A<B<C>> orderData = JSON.parseObject("json字符串",new TypeReference<A<B<C>>>(){});
舉例:
ApiResponse<List<CaseInfoVo>> initialCaseInfoApiResponse = JSONObject.parseObject(requestResult, new TypeReference<ApiResponse<List<CaseInfoVo>>>() {});
到了這里,關(guān)于fastJSON 字符串轉(zhuǎn)對象的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!