Android Json Parsing ( JSON Deserializing )
Get Arralist Example
Download the GSON library
Make sure you import this into your Android project as an imported library by going to:
Project > Properties > Java Build Path > Libraries > Add Jars…
Setup the Deserializer
Lets build our deserializer by using the following code, using the type “Gig” as an example:
Make model first like this
YourModel.class
public class YourModel
{
@SerializedName("name") public String name= "name";
}
String YourjsonData = "[Insert JSON data here]";
Gson gson = new Gson();
JSONObject j;
Gig gig = null;
try
{
j = new JSONObject(jsonData);
gig = gson.fromJson(YourjsonData.toString(), YourModel.class);}
catch(Exception e)
{
e.printStackTrace();
}
Get Arralist Example
YourModel.class
public class YourModel
{
@SerializedName("name") public String name= "name";
@SerializedName("arrylistmodel")public ListModel arraylistmodel= new ListModel()public class ListModel{
@SerializedName("name") public String name= "name";
}
}
No comments:
Post a Comment