[ {"serviceData": [ {"id": "1","service_name": "Plumber","act_stat": "1"},]}] how to get this json Structure
Asked
Active
Viewed 256 times
0
-
2Possible duplicate of [How to parse JSON Array (Not Json Object) in Android](https://stackoverflow.com/questions/18977144/how-to-parse-json-array-not-json-object-in-android) – Reaz Murshed Nov 27 '18 at 20:34
-
See the answer here - https://stackoverflow.com/a/53507481/3145960 – Reaz Murshed Nov 27 '18 at 20:34
3 Answers
1
String jsonString;
JSONArray jsonArray= new JSONArray(jsonString;);
for(int i=0;i<jsonArray.length();i++)
{
JSONObject jsono= (JSONObject) jsonArray.get(i);
JSONArray ServiceArray= (JSONArray ) jsono.get(i);
for(int j=0;j<ServiceArray.length();j++)
{
String id=jsonobject.getString("id");
String service_name=jsonobject.getString("service_name");
String act_stat=jsonobject.getString("act_stat");
}
}
You can refer this post : How to Parse the JSON String Android for more details

Taranjit Kaur
- 216
- 1
- 7
0
First of all get JSONObject from JSONArray and then get particular field from that JSONObject like below :
JSONObject jsonObj = new JSONObject(jsonStr);
SONArray jArray = jsonObj.getJSONArray("serviceData");
for (int i = 0; i < jArray.length(); i++) {
JSONObject jObject = jArray.getJSONObject(i);
String id = jObject.getString("id");
String service_name = jObject.getString("service_name");
String act_stat = jObject.getString("act_stat");
}

Rishav Singla
- 485
- 4
- 10

Abdomns
- 428
- 3
- 8
0
First of all get JSONObject from JSONArray and then get particular field from that JSONObject like below :
JSONArray array;
for(int n = 0; n < array.length(); n++)
{
JSONObject object = array.getJSONObject(n);
String id = object .getString("id");
String service_name = object .getString("service_name");
String act_stat = object .getString("act_stat");
}

Rishav Singla
- 485
- 4
- 10