How to use Google/GSON to convert a JSON string into Java POJO?

前端 未结 1 1371
既然无缘
既然无缘 2021-01-15 03:56

I have the following string:

{\"account\":{
    \"username\":\"ikevin2222\",
    \"birthdate\":\"2017-01-31T09:37:44.000Z\",
    \"gender\":true,
    \"email         


        
1条回答
  •  失恋的感觉
    2021-01-15 04:54

    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':

    convert your json or string to POJO

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

    0 讨论(0)
提交回复
热议问题