本文介绍了如何使用Google / GSON将JSON字符串转换为Java POJO?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



  {account:{
username:ikevin2222 ,
birthdate:2017-01-31T09:37:44.000Z,
gender:true,
emailaddresses:[{
emailaddress: aaa@bbb.com,
verificationcode:AAAAAA,
isverified:false
}]
}}

解决方案

使用) p>

现在添加依赖关系 compile'c​​om.google.code.gson:gson:2.6.2'



  Gson gson = new Gson (); 
POJOClass pojo = gson.fromJson(jsonObject.toString(),new TypeToken< POJOClass>(){} .getType());


I have the following string:

{"account":{
    "username":"ikevin2222",
    "birthdate":"2017-01-31T09:37:44.000Z",
    "gender":true,
    "emailaddresses": [{
        "emailaddress":"aaa@bbb.com",
        "verificationcode":"AAAAAA",
        "isverified":false
    }]
}}

How do I use Google/GSON to convert it to Java POJO?

解决方案

Generate your POJO by using http://www.jsonschema2pojo.org/ or by adding plugin in studio (https://github.com/Hexara/Json2Pojo)

now add dependencies compile 'com.google.code.gson:gson:2.6.2':

Gson gson = new Gson();
POJOClass pojo = gson.fromJson(jsonObject.toString(), new TypeToken<POJOClass>() {}.getType());

这篇关于如何使用Google / GSON将JSON字符串转换为Java POJO?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 10:26
查看更多