I'm trying to figure out how to parse this JSON array that has no name. I've already looked at this but i'm trying to use the Volley library to parse my data.
[
{
"name": "name1",
"employee":1,
},
{
"name": "name2",
"employee":2,
},
{
"name": "name3",
"employee":3,
}
]
The java code I have now is
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try{
JSONArray jsonArray = response.getJSONArray(???);
for(int i = 0; i <jsonArray.length(); i++){
JSONObject contact = jsonArray.getJSONObject(i);
String name = contact.getString("name");
int employee_ID = contact.getInt("employee");
}
textView.append(name + employee_ID );
}
}catch (JSONException e){
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("VOLLY", error.toString());
}
}
);
I'm not sure what to put for the parameters of response.getJSONArray() since my array has no title.