先要引入对应的jar,然后调用net.sf.json库的 ObjectMapper mapper = new ObjectMapper(); JavaType javaType = mapper.getTypeFactory().constructParametricType(List.class, ApprWritUnionFormModel.class); /*ListFormModel writUnionFormL
先要引入对应的jar,然后调用net.sf.json库的
ObjectMapper mapper = new ObjectMapper(); JavaType javaType = mapper.getTypeFactory().constructParametricType(List.class, ApprWritUnionFormModel.class); /*List<FormModel> writUnionFormList = JSON.parseArray(params, FormModel.class);*/ List<FormModel> writUnionFormList=new ArrayList<FormModel>(); try { writUnionFormList = (List<FormModel>)mapper.readValue(params, javaType); } catch (JsonParseException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
fastjson的简单用法,fastjson转换相对语法简单点,不过如果出现Bean类过大,或者在ie模式有时候会出现一些报错
List<FormModel> writUnionFormList = JSON.parseArray(params, FormModel.class);
附录,如果在ie出现中文乱码问题,可以参考我之前教程:https://www.jb51.net/article/168992.htm
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持自由互联。