0
{
  "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
}

this is my json string.I stored in String myjsonString, Approbvall_BE is my class. This is my code.

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);

after this line even s.o.p itself not working. Can anyone help me?.

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

3 回答 3

1

Use jsonschema2pojo to generate model for your JSON, and use the same code to deserilize it to java object

于 2013-06-15T04:09:00.003 回答
0

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

在 readvalue 方法中传递 json

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

这会将json转换为java

于 2013-06-15T05:19:09.320 回答
0
    String str = "Your json string";

JSONObject json = new JSONObject(str);

于 2013-06-15T04:17:22.417 回答