日期:2014-05-16  浏览次数:20408 次

JSON: property "xxx" has no getter method in class "..."
Exception in thread "main" net.sf.json.JSONException: java.lang.NoSuchMethodException: Property 'name' has no getter method
解决:声明bean为public class xxx,必须是public,我用默认类型(class xxx)都不行
json-lib.jar开发包使用:

依赖包:
commons-beanutils.jar;
commons-httpclient.jar;
commons-lang.jar;
ezmorph.jar;不少人使用时会提示net.sf.ezmorph.xxx找不到,就是缺这个:
morph-1.0.1.jar

相关链接:
http://json-lib.sourceforge.net/
http://ezmorph.sourceforge.net/
http://morph.sourceforge.net/

使用过程中问题:
1,把bean转化为json格式时老提示如下错误:
Exception in thread "main" net.sf.json.JSONException: java.lang.NoSuchMethodException: Property 'name' has no getter method
解决:声明bean为public class xxx,必须是public,我用默认类型(class xxx)都不行

2,Exception in thread "main" java.lang.NoSuchMethodError: org.apache.commons.lang.ArrayUtils.toObject([C)[Ljava/lang/Character;
原因:定义属性如下:private char[] options = new char[] { 'a', 'f' };好像不能处理这种类型的

3, private String func1 = "function(i){ return this.options[i]; }";
?? 和
?? private JSONFunction func2 = new JSONFunction(new String[] { "i" },
???? "return this.options[i];");
?? 转换后显示结果差不多:
?? {"func1":function(i){ return this.options[i];,"func2":function(i){ return this.options[i]; }}

测试类:
?
  1. import?java.util.ArrayList;??
  2. import?java.util.HashMap;??
  3. import?java.util.List;??
  4. import?java.util.Map;??
  5. ??
  6. import?net.sf.json.JSONArray;??
  7. import?net.sf.json.JSONObject;??
  8. ??
  9. public?class?Json?{??
  10. ????public?static?void?main(String[]?args)?{??
  11. ????????Json?j?=?new?Json();??
  12. ????????j.bean2json();??
  13. ????}??
  14. ??
  15. ????public?void?arr2json()?{??
  16. ????????
友情链接: 爱易网 云虚拟主机技术 云服务器技术 程序设计技术 开发网站 APP开发教程
Copyright © 2013-2024 爱易网页 当前在线:400人  网站在5时46分31秒内访问总人数:68799人 当前 57.53%  粤ICP备18100884号-2