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

  1. {
  2. "response": {
  3. "resultcode": "0",
  4. "errormsg": "查询成功",
  5. "poifrid": "3535353",
  6. "cardno": "545353535",
  7. "name": "gesrresge",
  8. "sex": "1",
  9. "birthday": "refwrefwr",
  10. "cardstatus": "0",
  11. "identityid": "6464646",
  12. "phone": "4353422"
  13. }
  14. }
  1. TestPerson person2 = JSON.parseObject(jsonObj.toString().toLowerCase(), TestPerson.class);

  

我的解决方法是:

1、检查内部类是不是static的。

2、检查有没有写构造方法。

3、先将bean对象转化成json字符串输出,将json字符串和自己的字符串做对比,看看哪里不一样。

  1.         TestPerson.Response response2 = new TestPerson.Response();
  2. response2.setSex("56");
  3. response2.setName("rg4g");
  4. response2.setSex("565");
  5. response2.setBirthday("190231313");
  6. response2.setCardno("t4t43t");
  7. response2.setCardstatus("3ffg3");
  8. response2.setErrormsg("uj67j764");
  9. response2.setIdentityid("54gg4");
  10. response2.setPatientid("99707");
  11. response2.setPhone("5t4t45");
  12. response2.setResultcode("0");
  13. TestPerson person = new TestPerson();
  14. person.setResponse(response2);
  15. Log.e("bean2json-string:",JSON.toJSONString(person));

 TestPerson.java如下:

  1. package com.kevinchan.fangding.Fragment;
  2.  
  3. import android.util.Log;
  4.  
  5. import java.io.Serializable;
  6.  
  7. /**
  8. * Created by Jackie on 2016/12/13.
  9. */
  10.  
  11. public class TestPerson implements Serializable {
  12.  
  13. public TestPerson() {
  14. // setResponse2(this.Response2);
  15. }
  16.  
  17. private Response response;
  18.  
  19. public void setResponse(Response response){
  20. this.response = response;
  21. }
  22. public Response getResponse(){
  23. return this.response;
  24. }
  25.  
  26. public static class Response {
  27. public Response(){
  28.  
  29. }
  30.  
  31. private String resultcode;
  32.  
  33. private String errormsg;
  34.  
  35. private String patientid;
  36.  
  37. private String cardno;
  38.  
  39. private String name;
  40.  
  41. private String sex;
  42.  
  43. private String birthday;
  44.  
  45. private String cardstatus;
  46.  
  47. private String identityid;
  48.  
  49. private String phone;
  50.  
  51. public void setResultcode(String resultcode){
  52. this.resultcode = resultcode;
  53. }
  54. public String getResultcode(){
  55. return this.resultcode;
  56. }
  57. public void setErrormsg(String errormsg){
  58. this.errormsg = errormsg;
  59. }
  60. public String getErrormsg(){
  61. return this.errormsg;
  62. }
  63. public void setPatientid(String patientid){
  64. this.patientid = patientid;
  65. }
  66. public String getPatientid(){
  67. return this.patientid;
  68. }
  69. public void setCardno(String cardno){
  70. this.cardno = cardno;
  71. }
  72. public String getCardno(){
  73. return this.cardno;
  74. }
  75. public void setName(String name){
  76. this.name = name;
  77. }
  78. public String getName(){
  79. return this.name;
  80. }
  81. public void setSex(String sex){
  82. this.sex = sex;
  83. }
  84. public String getSex(){
  85. return this.sex;
  86. }
  87. public void setBirthday(String birthday){
  88. this.birthday = birthday;
  89. }
  90. public String getBirthday(){
  91. return this.birthday;
  92. }
  93. public void setCardstatus(String cardstatus){
  94. this.cardstatus = cardstatus;
  95. }
  96. public String getCardstatus(){
  97. return this.cardstatus;
  98. }
  99. public void setIdentityid(String identityid){
  100. this.identityid = identityid;
  101. }
  102. public String getIdentityid(){
  103. return this.identityid;
  104. }
  105. public void setPhone(String phone){
  106. this.phone = phone;
  107. }
  108. public String getPhone(){
  109. return this.phone;
  110. }
  111.  
  112. }
  113. }

 注意: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. ubuntu下使用visual studio code来编译和调试C++

    最近想在linux上编译c++代码,自己却一直习惯window上的IDE.以前公司要我写Linux代码的时候,我一般都是用eclipse + CDT,而eclipse这东西吧,我个人感觉因为加载组件太 ...

  2. Asynchronous javascript and xml

    关于Ajax,学习了原生的ajax和JQ的ajax,如今,它已是无处不在,首先,我们知道开发或者使用的软件分为c/s和b/s两种,分别是客户端/服务端和浏览器端/服务端. 前者的优点是响应速度快,但是 ...

  3. Macbook下virtualenv无法使用解决办法

    Mac下删除自己安装的Python 删除Python框架sudo rm -rf /Library/Frameworks/Python.framework/Versions 删除Python程序sudo ...

  4. EI目录下载地址及保护密码

    EI目录下载地址:http://www.elsevier.com/solutions/engineering-village/content EI工作薄保护密码:AAAAABABAABD

  5. redis高可用分布式集群

    一,高可用 高可用(High Availability),是当一台服务器停止服务后,对于业务及用户毫无影响. 停止服务的原因可能由于网卡.路由器.机房.CPU负载过高.内存溢出.自然灾害等不可预期的原 ...

  6. Java三大框架的配置

    1. 首先是spring,右键项目-myeclipse-capabilitise-install spring etc.类似的就好,生成applicationContext.xml和spring一些类 ...

  7. css左右居中的几种常见方法

    本人是前端的新人,这是第一次写技术博客,各位大大,本文有错误请指正,手中的板砖尽量轻拍,我怕疼~~ 对于水平居中和垂直居中我也用过很多方法,但是有的时候管用有的时候又嗝屁不好使了.涉及到的情况很多,所 ...

  8. spring 事务问题

    今天碰到一个奇怪的问题,在service中执行方法,调用了两次dao,前面是save,在save后面抛错,竟然没回滚,难道不是一个事务? 后来网上查资料,发现spring的事务回滚必须是运行时异常Ru ...

  9. linux 关于用户与组的操作

    1.添加用户: useradd  handongyu 2.查看所有用户 cat  /etc/passwd   查看某一用户用 cat /etc/passwd |grep root 3.查看所有组 ca ...

  10. java自编时间工具类

    package timeTools; import java.text.ParseException; import java.text.SimpleDateFormat; import java.u ...