我的情况是:解析第一层数据成功,解析第二层嵌套的数据失败。如:

{
"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对象解析出错的检查方法的更多相关文章

  1. hutool-all 包把实体Bean转化成字符串,以及把字符串转化成Bean对象

    GxyJobEntity gxyJobEntity1 = new GxyJobEntity(); gxyJobEntity1.setUserId("user001"); gxyJo ...

  2. fastjson将json字符串转化为java对象

    目录 一.导入一个fastjson的jar包 二.Json字符串格式 三.根据json的格式创建Java类 四.给java类的所有属性添加setter方法 五.转换为java对象 一.导入一个fast ...

  3. [MVC_Json序列化]Json字符串反序列化成C#对象

    上一篇中有Json序列化相关问题得到了解决. 那么结果集为Json串时,如何将Json串转成C#对象呢? 现举例说明: -现有如下字符串数据 string k = "{\"ring ...

  4. fastjson将json字符串转化成map的五种方法

    package com.zkn.newlearn.json; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObj ...

  5. fastjson 将json字符串转化成List<Map<String, Object>>

    亲测可行,如下: JSON.parseObject(jsonstr, new TypeReference<List<Map<String, Object>>>() ...

  6. C#将Json字符串反序列化成List对象类集合

    摘自:http://blog.csdn.net/cdefg198/article/details/7520398 using System.IO; using System.Web.Script.Se ...

  7. js将json字符串转化成json对象的方法

    js将json字符串转化成json对象的方法: JSON.parse(jsonObject)

  8. JSON字符串反序列化成对象_部分属性值反序列化失败

    简介:本人在开发webapi接口时遇到了:一个复杂的Json字符串在反序列化为对象时报,无法发序列化其中的一个属性对象? 使用方法: InternalRecommendRequestFormModel ...

  9. fastjson转换json字符串key的首字母小写变大写的解决办法

    https://blog.csdn.net/erbao_2014/article/details/53688934 问题描述在开发过程中,由于接口文档的描述,要求json字符串的key首字母为大写,而 ...

随机推荐

  1. 使用jenkins 插件自动部署项目至tomcat

    前面使用maven.ant编译项目就不说,只说一下使用jenkins的插件自动部署项目 1.首先jenkins安装插件Deploy to container Plugin ,下载地址为:https:/ ...

  2. 剑指Offer:面试题34——丑数(java实现)

    问题描述: 把只包含因子2.3和5的数称作丑数(Ugly Number).例如6.8都是丑数,但14不是,因为它包含因子7. 习惯上我们把1当做是第一个丑数.求按从小到大的顺序的第N个丑数. 思路1: ...

  3. KMS服务器激活Windows和Office2013EnterprisePlus

    KMS服务器激活Windows和Office2013EnterprisePlus 参考了文档 http://wenku.baidu.com/view/0cb2602358fb770bf68a5501. ...

  4. 多个DLL合并成一个DLL

    多个DLL合并成一个DLL,把DLL合并到Exe中的解决方案 1:) 下载 http://download.microsoft.com/download/1/3/4/1347C99E-9DFB-425 ...

  5. MySql绿色版下载,安装,配置详解

    下载完成之后解压,楼主用的版本是:mysql-5.7.15-winx64 解压完在根目录下建立一个data文件夹和my-default.ini my-default.ini里面的内容如下:(红色内容根 ...

  6. python中logging

    1.root logger以及logger斧子关系    http://www.pythonclub.org/modules/logging #coding=utf-8 __author__ = 'n ...

  7. centos 7 挂载大硬盘

    对硬盘sdb进行分区 parted -a optimal /dev/sdb 使用GPT格式 mklabel gpt 建立一个主分区 mkpart primary - 显示分区信息 print 退出 q ...

  8. cs11_c++_lab7

    wcount.cc #include <iostream> #include <map> #include <string> #include <algori ...

  9. mysql 忘记root 密码的解决方法

    LINUX 1.切换root 用户 2.停止mysqld 服务 /etc/inid.d mysqld stop 3.跳过验证登录 mysqld_safe --skip-grant-tables &am ...

  10. iBatis的SQL注入

    sqlMap中尽量不要使用$;$使用的是Statement(拼接字符串),会出现注入问题.#使用的是PreparedStatement(类似于预编译),将转义交给了数据库,不会出现注入问题:.前者容易 ...