У меня есть пример формата Json здесь, и я хотел бы проанализировать с помощью залпа Android, но я застрял с ошибкой: при вводе типа org.json.JSONObject не может быть преобразован в JSONArray
{
"entry": {
"": {
"": "http:\/\/www.w3.org\/2005\/Atom",
"m": "http:\/\/schemas.microsoft.com\/ado\/2007\/08\/dataservices\/metadata",
"d": "http:\/\/schemas.microsoft.com\/ado\/2007\/08\/dataservices"
},
"FOO_BLOCK": {
"BAR_xmlbase": "https:\/\/ab.com:443\/dap\/opu\/odata\/dap\/BATCH_SRV\/"
},
"id": {
"TEXT": "https:\/\/ab.com:443\/dap\/opu\/odata\/dap\/BATCH_SRV\/BatchSet('1000')"
},
"title": {
"FOO_BLOCK": {
"BAR_type": "text"
},
"TEXT": "BatchSet('1000')"
},
"updated": {
"TEXT": "2018-06-05T13:45:24Z"
},
"category": {
"FOO_BLOCK": {
"BAR_term": "BATCH_SRV.Batch",
"BAR_scheme": "http:\/\/schemas.microsoft.com\/ado\/2007\/08\/dataservices\/scheme"
},
"TEXT": "NULL"
},
"link": {
"FOO_BLOCK": {
"BAR_href": "BatchSet('1000')",
"BAR_rel": "self",
"BAR_title": "Batch"
},
"TEXT": "NULL"
},
"content": {
"FOO_BLOCK": {
"BAR_type": "application\/xml"
},
"mproperties": {
"dCharg": {
"TEXT": 1000
},
"dICharg": {
"TEXT": 1000
},
"dMaktx": {
"TEXT": "No Material description avaibalbe"
},
"dStatus": {
"TEXT": "Batch is unrestricted"
},
"dStock": {
"TEXT": "NULL"
}
}
}
}
}
Ниже приведен код, который я написал в Android.
JsonObjectRequest arrReq = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject >() {
@Override
public void onResponse(JSONObject response) {
Log.e("FD", response.toString());
// Check the length of our response (to see if the user has any repos)
// Process the JSON
try{
// Get the JSON array
JSONArray jsonArray = response.getJSONArray("entry");
Log.e("FD", jsonArray.toString());
// Loop through the array elements
for(int i=0;i<array.length();i++){
// Get current json object
JSONObject data = array.getJSONObject(i);
String Charg = student.getString("Charg");
String Status = student.getString("Status");
// Display the formatted json data in text view
addToRepoList(Charg , Status );
}
}catch (JSONException e){
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// If there a HTTP error then add a note to our repo list.
setRepoListText("Error while calling REST API");
Log.e("Volley", error.toString());
}
}
);
Но я получаю ошибки при разборе его в Android.Ошибка: JSONObject не может быть преобразован в JSONArray
Может кто-нибудь предоставить пример кода для анализа этого массива json.