◎위챗 : speedseoul
http://mobilesiri.com/json-parsing-in-android-using-android-studio/
usually, most of the application require interchanging of data from the server. During interchanging data, well formatted and structured data is required. JSON parsing is good and well structured, lightweight and easy to parse and human readable. In this tutorial, we will focus how to parse to JSON in Android Studio.
We are going to use very simple JSON in this tutorial, which contains list of students while each node have id,name,gender and phone attributes of a student.
{
"studentinfo": [
{
"id": "S99",
"sname": "Adam Jam" ,
"semail": "adam.jam@abc.com",
"address": "House #33, ABC Lane, ABC CITY 06987",
"gender" : "male",
"phone": {
"mobile": "+1 1234997890",
"home": "00 123456",
"office": "00 321654"
}
},
{
"id": "S101",
"sname": "Archbould Tom",
"semail": "archbould.tom@axy.com",
"address": "House #33, ABC Lane, ABC CITY 06987",
"gender" : "male",
"phone": {
"mobile": "+1 1234599890",
"home": "00 123456",
"office": "00 321654"
}
}
]
}
Usually, JSON contains two types of nodes, JSONArray and JSONObject. So while parsing the JSON node we have to use the appropriate method. If JSON starts from [ represent JSONArray and if starts from { represent JSONObject.So if JSON starting from [, we use the getJSONArray method to parse. and same as if JSON start with { we should use the getJSONObject method.