JSONArray 转list 可以通过如下简便方法进行
JSONArray programsArray = jsonobject.getJSONArray("programs");
List<Programs> list = (List) JSONArray.toCollection(programsArray, Programs.class);
转换过程中容易产生NoSuchMethodException 异常, 产生异常的原因是 对象 Programs 缺少无参构造方法。
添加上即可
public Programs(){
}
net.sf.json.JSONException: java.lang.NoSuchMethodException: com.cnlive.mz.ips.model.Programs.<init>()
JSON转List技巧与注意事项
本文介绍了一种将JSONArray转换为List的简便方法,并详细解释了在此过程中可能遇到的NoSuchMethodException异常及其解决办法——即确保目标类拥有无参构造方法。
7009

被折叠的 条评论
为什么被折叠?



