JAVA JSON String to Object 转换中的集合
2012-03-02 12:28
501 查看
如果要转换到的Bean类中含有类似ArrayList、Map、List这样的集合时,要对集合进行处理,否则会报“net.sf.ezmorph.bean.MorphDynaBean cannot be cast to XXX”
这样的异常。
处理方法如下:
1.定义一个Map
2.向Map中put Bean中集合成员名和对应的类型
3.在调用JSONObject.toBean()时加入mymap参数
OK
这样的异常。
处理方法如下:
1.定义一个Map
Map <String,Class> mymap = new HashMap<String,Class>();
2.向Map中put Bean中集合成员名和对应的类型
mymap.put("content",ClientInfo.class); //我这里的成员名为content 对应的类为ClientInfo.class,具体值要跟据你自己的来定。
3.在调用JSONObject.toBean()时加入mymap参数
GetUserInfo info=(GetUserInfo)JSONObject.toBean(obj,GetUserInfo.class,mymap);
OK
相关文章推荐
- JAVA JSON String to Object 转换中的集合
- JSONObject转换Int类型--java.lang.Integer cannot be cast to java.lang.String
- Value of type java.lang.String cannot be converted to JSONObject 异常
- 将Json字符串转换为ASP对象(parse json string to asp object) 转载
- Json解析异常处理方式(JSONException: Value of type java.lang.String cannot be converted to JSONObject)
- java和js中JSONObject,JSONArray,Map,String之间转换——持续更新中
- Java中将实现string到JSONObject的转换
- java中JSONArray、JSONObject、List、String之间的转换
- Json解析异常处理方式(JSONException: Value of type java.lang.String cannot be converted to JSONObject)
- JSONException: java.lang.String cannot be converted to JSONObject
- JSONException: Value of type java.lang.String cannot be converted to JSONObject
- Java将List,Set,Arrary,String,Object转换为JSON格式
- Value of type java.lang.String cannot be converted to JSONObject
- Json解析异常处理方式(JSONException: Value of type java.lang.String cannot be converted to JSONObject)
- org.json.JSONException: Value ok of type java.lang.String cannot be converted to JSONObject:
- JSONException:java.lang.String cannot be converted to JSONObject解决办法
- java和js中JSONObject,JSONArray,Map,String之间转换
- java和js中JSONObject,JSONArray,Map,String之间转换
- org.json.JSONException: Value ok of type java.lang.String cannot be converted to JSONObject: [Caugh
- of type java.lang.String cannot be converted to JSONObject: Android