我有以下字符串:
{"account":{
"username":"ikevin2222",
"birthdate":"2017-01-31T09:37:44.000Z",
"gender":true,
"emailaddresses": [{
"emailaddress":"aaa@bbb.com",
"verificationcode":"AAAAAA",
"isverified":false
}]
}}
如何使用Google / GSON将其转换为Java POJO?
答案 0 :(得分:3)
使用http://www.jsonschema2pojo.org/或在工作室中添加插件(https://github.com/Hexara/Json2Pojo)生成您的POJO
现在添加依赖项compile 'com.google.code.gson:gson:2.6.2'
:
将您的json或字符串转换为POJO
Gson gson = new Gson();
POJOClass pojo = gson.fromJson(jsonObject.toString(), new TypeToken<POJOClass>() {}.getType());