how to parse sub array like as getString("sub") using gson lib in android.
<pre>
{
"name" : "abc";
"class" : "xyz";
"address" : {[
"add" : "1";
"sub" :["abc"];
]}
}
</pre>
how to parse sub array like as getString("sub") using gson lib in android.
<pre>
{
"name" : "abc";
"class" : "xyz";
"address" : {[
"add" : "1";
"sub" :["abc"];
]}
}
</pre>
First of all you should reduce your JSON to correct form:
{
"name" : "abc",
"class" : "xyz",
"address" : [
{"add" : "1",
"sub" :["abc"]}
]
}
Now, create objects with following structure:
class Foo{
String name;
String class;
Address[] address;
}
class Address{
String add;
String[] sub;
}
And on this step you can easily parse JSON to an object, by calling this line:
Foo foo = new Gson().fromJson(json, Foo.class);
This is invalid JSON, some combination of XML and JSON. This is the way how to parse JSON in Android How to parse json string in Android? And this is JSON schema wiki post https://en.wikipedia.org/wiki/JSON