fastjson将json字符串转化成bean对象解析出错的检查方法
我的情况是:解析第一层数据成功,解析第二层嵌套的数据失败。如:
{
"response": {
"resultcode": "0",
"errormsg": "查询成功",
"poifrid": "3535353",
"cardno": "545353535",
"name": "gesrresge",
"sex": "1",
"birthday": "refwrefwr",
"cardstatus": "0",
"identityid": "6464646",
"phone": "4353422"
}
}
TestPerson person2 = JSON.parseObject(jsonObj.toString().toLowerCase(), TestPerson.class);
我的解决方法是:
1、检查内部类是不是static的。
2、检查有没有写构造方法。
3、先将bean对象转化成json字符串输出,将json字符串和自己的字符串做对比,看看哪里不一样。
TestPerson.Response response2 = new TestPerson.Response();
response2.setSex("56");
response2.setName("rg4g");
response2.setSex("565");
response2.setBirthday("190231313");
response2.setCardno("t4t43t");
response2.setCardstatus("3ffg3");
response2.setErrormsg("uj67j764");
response2.setIdentityid("54gg4");
response2.setPatientid("99707");
response2.setPhone("5t4t45");
response2.setResultcode("0");
TestPerson person = new TestPerson();
person.setResponse(response2);
Log.e("bean2json-string:",JSON.toJSONString(person));
TestPerson.java如下:
package com.kevinchan.fangding.Fragment; import android.util.Log; import java.io.Serializable; /**
* Created by Jackie on 2016/12/13.
*/ public class TestPerson implements Serializable { public TestPerson() {
// setResponse2(this.Response2);
} private Response response; public void setResponse(Response response){
this.response = response;
}
public Response getResponse(){
return this.response;
} public static class Response {
public Response(){ } private String resultcode; private String errormsg; private String patientid; private String cardno; private String name; private String sex; private String birthday; private String cardstatus; private String identityid; private String phone; public void setResultcode(String resultcode){
this.resultcode = resultcode;
}
public String getResultcode(){
return this.resultcode;
}
public void setErrormsg(String errormsg){
this.errormsg = errormsg;
}
public String getErrormsg(){
return this.errormsg;
}
public void setPatientid(String patientid){
this.patientid = patientid;
}
public String getPatientid(){
return this.patientid;
}
public void setCardno(String cardno){
this.cardno = cardno;
}
public String getCardno(){
return this.cardno;
}
public void setName(String name){
this.name = name;
}
public String getName(){
return this.name;
}
public void setSex(String sex){
this.sex = sex;
}
public String getSex(){
return this.sex;
}
public void setBirthday(String birthday){
this.birthday = birthday;
}
public String getBirthday(){
return this.birthday;
}
public void setCardstatus(String cardstatus){
this.cardstatus = cardstatus;
}
public String getCardstatus(){
return this.cardstatus;
}
public void setIdentityid(String identityid){
this.identityid = identityid;
}
public String getIdentityid(){
return this.identityid;
}
public void setPhone(String phone){
this.phone = phone;
}
public String getPhone(){
return this.phone;
} }
}
注意:bean对象传递时类要序列化,实现Serializable类。implements Serializable。同时内部类也一定要序列化。
fastjson将json字符串转化成bean对象解析出错的检查方法的更多相关文章
- hutool-all 包把实体Bean转化成字符串,以及把字符串转化成Bean对象
GxyJobEntity gxyJobEntity1 = new GxyJobEntity(); gxyJobEntity1.setUserId("user001"); gxyJo ...
- fastjson将json字符串转化为java对象
目录 一.导入一个fastjson的jar包 二.Json字符串格式 三.根据json的格式创建Java类 四.给java类的所有属性添加setter方法 五.转换为java对象 一.导入一个fast ...
- [MVC_Json序列化]Json字符串反序列化成C#对象
上一篇中有Json序列化相关问题得到了解决. 那么结果集为Json串时,如何将Json串转成C#对象呢? 现举例说明: -现有如下字符串数据 string k = "{\"ring ...
- fastjson将json字符串转化成map的五种方法
package com.zkn.newlearn.json; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObj ...
- fastjson 将json字符串转化成List<Map<String, Object>>
亲测可行,如下: JSON.parseObject(jsonstr, new TypeReference<List<Map<String, Object>>>() ...
- C#将Json字符串反序列化成List对象类集合
摘自:http://blog.csdn.net/cdefg198/article/details/7520398 using System.IO; using System.Web.Script.Se ...
- js将json字符串转化成json对象的方法
js将json字符串转化成json对象的方法: JSON.parse(jsonObject)
- JSON字符串反序列化成对象_部分属性值反序列化失败
简介:本人在开发webapi接口时遇到了:一个复杂的Json字符串在反序列化为对象时报,无法发序列化其中的一个属性对象? 使用方法: InternalRecommendRequestFormModel ...
- fastjson转换json字符串key的首字母小写变大写的解决办法
https://blog.csdn.net/erbao_2014/article/details/53688934 问题描述在开发过程中,由于接口文档的描述,要求json字符串的key首字母为大写,而 ...
随机推荐
- tomcat8和7关于自定义tag的处理区别
今天将一直运行在tomcat-7.0.29(jdk1.6)上的应用迁移到tomcat-8.0.26(jdk1.7)上面,老显示如下错误: org.apache.jasper.JasperExcepti ...
- md5算法
md5算法 不可逆的:原文-->密文.用系统的API可以实现: 123456 ---密文 1987 ----密文: 算法步骤: 1.用每个byte去和11111111做与运算并且得到的是int类 ...
- js实现表单验证 常用JS表单验证
CSS代码 @charset "gb2312"; /* CSS Document */ body,dl,dt,dd,div,form {padding:;margin:;} #he ...
- css3动画3
1.transition过渡动画 2.@keyframes关键帧动画,配合transform.animation使用
- JAVA 通过LDAP获取AD域用户及组织信息
因为工作需求近期做过一个从客户AD域获取数据实现单点登录的功能,在此整理分享. 前提:用户可能有很多系统的情况下,为了方便账号的统一管理使用AD域验证登录,所以不需要我们的系统登录,就需要获取用户的A ...
- 用VBS实现公司自动打卡
公司每天要求早晚打卡,方式是登录某一个页面,然后点击上面的圈圈,如下图: 每天都要打开书签,登录这个页面,然后打卡...这么重复性的工作,怎么能是程序员天天干的事情呢(其实是我太懒了),那么就尝试让程 ...
- Java web--Filter过滤器分IP统计访问次数
分IP统计访问次数即网站统计每个IP地址访问本网站的次数. 分析 因为一个网站可能有多个页面,无论哪个页面被访问,都要统计访问次数,所以使用过滤器最为方便. 因为需要分IP统计,所以可以在过滤器中创建 ...
- JAVAC 命令详解(转)
本文来自:http://www.cnblogs.com/JeffChen/archive/2008/01/16/1041783.html 结构 javac [ options ] [ sourcefi ...
- 线程操作UI界面的方法
以前一般都是用BeginInvoke来刷新UI界面,现在采用 SynchronizationContext 来刷新,写起来清楚多了. SynchronizationContext synchroniz ...
- 微信支付开发-当前页面的URL未注册
微信支付的开发设置要求设置微信支付可以发起的目录. 当出现“当前页面的URL未注册”的错误时,检查你的授权目录(一般是未填写或填写有误),注意要二级或者三级目录完全匹配.