I have a JSON string of this format
{
"user": "sam",
"password": "abcd1234",
"categories":
[
{
"fruit name": "watermelon"
},
{
"fruit name":"jackfruit"
},
{
"fruit name": "kiwi"
}
],
"store":"SPROUTS"
}
I was thinking I create a class of Structure like this
class Structure {
String user;
String password;
String store;
private Structure() {
this.user = "sam";
this.password = "abcd1234";
this.store = "SPROUTS";
}
}
And to parse the JSON, I can simply do it through Moshi through the following lines of code:
Moshi moshi = new Moshi.Builder().build();
Structure structure = new Structure();
String json = moshi.adapter(Structure.class).indent(" ").toJson(structure);
But, I also want to pass categories from my given JSON into this. How do I use categories with the same code? Also, what modifications are needed from my class structure?