繁体   English   中英

如何将JSON字符串转换为Java对象

[英]How to convert json string to java object

{
  "application_num" : 185,
  "age" : 35,
  "mobile_num" : "9943847180",
  "active" : null,
  "photo" : null,
  "bytes" : null,
  "creator" : null,
  "modifier" : null,
  "modifiedby" : null,
  "updatedby" : null,
  "cus_first_name" : "firstname",
  "cus_last_name" : "lastname",
  "sex" : "Male",
  "profession" : "profession",
  "designation" : "designation",
  "work_place_address" : "workkkkkkkkkk",
  "phone_number" : "044222222222",
  "resi_address" : "resssssssssssssi",
  "membership_type" : "Silver",
  "debitbal" : "100022",
  "dueamt" : "1002",
  "renewaldate" : "2013-06-13",
  "photoinputstream" : null
}

这是我的json字符串。我存储在String myjsonStringApprobvall_BE是我的课程。 这是我的代码。

Gson gson=new Gson(); 
//convert the json string back to object
Approval_BE app_be = gson.fromJson(myjsonString, Approval_BE.class);
System.out.println("print"+app_be.cus_first_name);

在这条线之后,甚至自己也无法正常工作。 谁能帮我?。

Approval_BE app_be = gson.fromJson(myjsonString, Approval_BE.class);

使用jsonschema2pojo生成JSON模型,并使用相同的代码将其反序列化为Java对象

    String str = "Your json string";

JSONObject json =新的JSONObject(str);

导入org.codehaus.jackson.map.ObjectMapper;

在readvalue方法中传递json

用户user = new ObjectMapper()。readValue(json,User.class);

这将json转换为java

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM