0

I am trying to send an HTTP request and get some data in response. Usually, I just create a class for the response, but now my response contains 5 classes into one field. Generally, the response contains only a few fields(string or integer) but now It contains classes and lists. I am using Retrofit2 in Android Studio.

{
"data": {
    “example”:31;
        },
        " example ": {
                   “example”:31;
     },
        " example ": {
            “example”:31;
        },
    }
},
"errors": false,
                       “example”:31;
       } }
Michael A.
  • 45
  • 8
  • What does the response look like? Can you provide an example JSON? – jsamol Aug 06 '19 at 12:40
  • I edited first post – Michael A. Aug 06 '19 at 12:47
  • Please provide proper json format & also it contains error – Jignesh Mayani Aug 06 '19 at 12:55
  • Have you tried creating such a response with nested classes and list on your own? It doesn't really seem like more than parsing json with nested objects, just first example from the Google results: https://stackoverflow.com/questions/32942661/how-can-retrofit-2-0-parse-nested-json-object – jsamol Aug 06 '19 at 13:02

2 Answers2

0

Try this solution i think its help you to resolve the query Retrofit and extracting nested API objects

RanaUmer
  • 561
  • 5
  • 9
0

Try out using Moshi or Gson with Retrofit for parsing (Moshi preferred) - there are many tutorials about it, eg: https://proandroiddev.com/moshi-with-retrofit-in-kotlin-%EF%B8%8F-a69c2621708b

You can also use plugin for Android Studio which makes process of creating classes for GSON / Moshi a lot easier: JsonToKotlinClass (https://plugins.jetbrains.com/plugin/9960-json-to-kotlin-class-jsontokotlinclass-)

BTW: Make sure your example json String is actually correctly created: https://jsonformatter.curiousconcept.com/

Janusz Hain
  • 597
  • 5
  • 18