Reputation: 1606
I have json like that:
"fields": [
[
{
"id": "11111"
},
{
"name": "dsfafds"
},
{
"description": "sdfadfas"
}
],
]
{
"id": "11111"
},
{
"name": "dsfafds"
},
{
"description": "sdfadfas"
}
],
........
So each field is an object, is there an easy way to parse it to object like:
class Json {
private String id;
private String name;
......
}
I know about gson adapters, but I would like to reduce the source code, maybe there is an easier way.
Upvotes: 0
Views: 91
Reputation: 490
You will probably need something like this too.
public class Example {
private List<Json> fields = null;
public List<Json> getFields() {
return fields;
}
public void setFields(List<Json> fields) {
this.fields = fields;
}
}
Json to Pojo is a very useful website when it comes to converting Json to PlainOldJavaObjects. You just copy paste the Json response select Gson as annotation style and you're golden. You can try it.
Additional code for second object:
public class Json {
private String id;
private String name;
private String description;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
JSON should look something like this.
{
"fields": [
{
"id": "11111",
"name": "dsfafds",
"description": "sdfadfas"
}
,
{
"id": "11111",
"name": "dsfafds",
"description": "sdfadfas"
}
]
}
Upvotes: 1