使用FastJson解析Json数据

前端之家收集整理的这篇文章主要介绍了使用FastJson解析Json数据前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
fastjson 是一个性能极好的用 Java 语言实现的 JSON 解析器和生成器,来自 阿里巴巴的工程师开发。

主要特点

  • 快速FAST (比其它任何基于Java的解析器和生成器更快,包括jackson

  • 强大(支持普通JDK类包括任意Java Bean Class、Collection、Map、Date或enum)

  • 零依赖(没有依赖其它任何类库除了JDK)


一 、生成Json:
JavaBean、List<JavaBean>、List<String>、List<Map<String,Object>>
[java] view plain copy
  1. StringjsonString=JSON.toJSONString(obj);

二、解析Json:
(1)JavaBean
(2)List<JavaBean>
    {"totalRecords":2615,
copy
"result":{"code":"200","status":"success"},
  • "list":[{"unuAbnId":"0bcd930f-014c-1000-e003-5f160a0d0114",
  • "entNo":"1c2e4ca8-00fa-1000-e000-74590a76bf0f",248)"> "regNO":"442000600169663",108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> "entName":"x",248)"> "entType":"9910",108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> "speCause":"3",248)"> "abnTime":"Mar13,201512:00:00AM",108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> "decOrg":"442020",248)"> "entNameUrl":"<ahref=\"..",108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> "auditingFileNo":"15000684990326",248)"> "abnormalID":"fd74013d-014b-1000-e00a-72970a0d0114"},{...},...],108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> "pageNo":1,248)"> "pageSize":8,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> "url":"main/abnInfoPage",248)"> "selList":[{"unuAbnId":"0bcd930f-014c-1000-e003-5f0f0a0d0114",108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> "entNo":"16da9629-0131-1000-e005-3effc0a803a8",248)"> "regNO":"442000602187424",248)"> "entNameUrl":"<ahref=\"..\">",108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> "auditingFileNo":"15000684990319",108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> "topPageNo":1,248)"> "totalPages":327,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> "previousPageNo":0,248)"> "nextPageNo":2,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> "bottomPageNo":327
  • }
  • 其中list含有2615条数据,selList含有8条数据,目标是提取selList中entNameUrl的链接(不含a href=)
    外层是JSONObject,里面的list和selList是JSONArrary,再里面是JSONObject。其中的result也是JSONObject
    在setter方法中可以进一步进行处理
    Link类中可以包含abnTime、entName、regNO等属性和对应的getter和setter方法,FastJson能自动映射。
    通过下面的方法也可以处理:
    原文链接:https://www.f2er.com/json/289491.html

    猜你在找的Json相关文章