fastjson 解析 字符串 为对象

1. parseObject

解析为一个对象。

示例:

String json = new String(Files.readAllBytes(Paths.get(getRoodDir() + "config.json")), StandardCharsets.UTF_8);
ConfigObj obj = JSONObject.parseObject(json,ConfigObj.class);


2.parseArray

解析为对象数组

数组数据形式类似如下:

[{
  "configName": "范围筛选",
  "paramName": "range",
  "type": "过滤"
}, {
  "configName": "排序选择",
  "paramName": "sort",
  "type": "排序"
}]

解析为数组示例:

List<ConfigObj> configObjs = JSONArray.parseArray(json, ConfigObj.class);










原文地址:https://www.cnblogs.com/betterwgo/p/13353158.html