Wednesday, December 2, 2015

JSON Parsing in Android

Parse data from server is many type like XML,DOM and JSON but JSON Parsing widely used, this topic we discuss JSON PARSING.

How to Parse JSON Object:

first we get data from server afterthat we parse, in JSON start with Object or Array.
{ }   =   Object

[ ]  = Array

so we check data is object or array.

    String result=  {"response":"100","data" : "Sucess"} 

It is start with object so first object parse then string.

try {
    JSONObject json = new JSONObject(result);
       String response= json.getString("response");                                   
       String data= json.getString("data");      
} catch (JSONException e) {
    e.printStackTrace();
}
we get response = 100;
and data= Sucess


No comments :

Post a Comment