[英]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 myjsonString
, Approbvall_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.