Search code examples
androidkotlinandroid-recyclerviewgraphqlgraphql-java

How to get JSON object elements from GraphQL API call?


I have API result like in this image. I want to get key and value from extraInformation and apply them into a recycler view. What is the best way to do it?

https://i.sstatic.net/RFmSX.png


Solution

  • You can create a Model class for your Json response. You can tale help from https://www.jsonschema2pojo.org/ site to create POJO class (model class)

    And then when you are parsing the response you Gson Library (google's library to work with Json data) to parse your Json response to Model class and then when you have the Data in Java/Kotlin object pass that information to RecylerView Adapter and then call notifyDatasetchange on adapter.

    ModelClass - > Parse Json to Object -> Pass to Adapter -> call Notify on adapter