我正在尝试从服务器获取数据,但无法获取
{
"call_duration_category": {
"0": 0,
"11-30": 0,
"0-10": 0,
"61-180": 0,
"31-60": 0,
"180+": 0
},
"user_call_data": [
{
"user_id": 17,
"prospect_number": "+919958561247",
"call_type": "out_going",
"talk_time": 30,
"start_datetime": "1970-01-01T05:30:00Z",
"end_datetime": "2019-06-16T09:13:50Z",
"creation_datetime": "2019-06-16T03:43:50.455108Z"
},
{
"user_id": 17,
"prospect_number": "+919718118877",
"call_type": "incoming",
"talk_time": 30,
"start_datetime": "2019-06-16T09:48:46Z",
"end_datetime": "2019-06-16T09:50:15Z",
"creation_datetime": "2019-06-16T04:20:16.527227Z"
},
{
"user_id": 17,
"prospect_number": "+919582647324",
"call_type": "incoming",
"talk_time": 30,
"start_datetime": "2019-06-16T10:02:25Z",
"end_datetime": "2019-06-16T10:03:34Z",
"creation_datetime": "2019-06-16T04:33:35.313637Z"
},
{
"user_id": 17,
"prospect_number": "+917428268915",
"call_type": "out_going",
"talk_time": 30,
"start_datetime": "1970-01-01T05:30:00Z",
"end_datetime": "2019-06-16T10:12:33Z",
"creation_datetime": "2019-06-16T04:42:34.022740Z"
},
{
"user_id": 17,
"prospect_number": "+919958561247",
"call_type": "incoming",
"talk_time": 30,
"start_datetime": "2019-06-16T10:14:39Z",
"end_datetime": "2019-06-16T10:15:03Z",
"creation_datetime": "2019-06-16T04:45:03.013636Z"
},
{
"user_id": 17,
"prospect_number": "+917428268915",
"call_type": "incoming",
"talk_time": 30,
"start_datetime": "2019-06-16T10:28:19Z",
"end_datetime": "2019-06-16T10:30:26Z",
"creation_datetime": "2019-06-16T05:00:26.615132Z"
},
{
"user_id": 17,
"prospect_number": "+919582647324",
"call_type": "incoming",
"talk_time": 30,
"start_datetime": "2019-06-16T11:13:27Z",
"end_datetime": "2019-06-16T11:13:44Z",
"creation_datetime": "2019-06-16T05:43:44.646805Z"
},
{
"user_id": 17,
"prospect_number": "+919990925305",
"call_type": "out_going",
"talk_time": 30,
"start_datetime": "2019-06-16T11:13:27Z",
"end_datetime": "2019-06-16T11:14:10Z",
"creation_datetime": "2019-06-16T05:44:10.243103Z"
},
{
"user_id": 17,
"prospect_number": "+919582647324",
"call_type": "out_going",
"talk_time": 30,
"start_datetime": "2019-06-16T11:13:27Z",
"end_datetime": "2019-06-16T11:14:36Z",
"creation_datetime": "2019-06-16T05:44:36.707062Z"
},
{
"user_id": 17,
"prospect_number": "+917428268915",
"call_type": "out_going",
"talk_time": 30,
"start_datetime": "2019-06-16T11:13:27Z",
"end_datetime": "2019-06-16T11:15:34Z",
"creation_datetime": "2019-06-16T05:45:33.999173Z"
},
{
"user_id": 17,
"prospect_number": "+917428268915",
"call_type": "incoming",
"talk_time": 30,
"start_datetime": "2019-06-16T11:20:30Z",
"end_datetime": "2019-06-16T11:21:28Z",
"creation_datetime": "2019-06-16T05:51:29.083218Z"
},
{
"user_id": 17,
"prospect_number": "+917210700848",
"call_type": "out_going",
"talk_time": 30,
"start_datetime": "2019-06-16T11:20:30Z",
"end_datetime": "2019-06-16T11:22:05Z",
"creation_datetime": "2019-06-16T05:52:05.179083Z"
},
{
"user_id": 17,
"prospect_number": "+919582647324",
"call_type": "out_going",
"talk_time": 30,
"start_datetime": "2019-06-16T11:20:30Z",
"end_datetime": "2019-06-16T11:24:46Z",
"creation_datetime": "2019-06-16T05:54:46.443063Z"
},
{
"user_id": 17,
"prospect_number": "+917428268915",
"call_type": "missed_call",
"talk_time": 45,
"start_datetime": "1970-01-01T05:30:00Z",
"end_datetime": "2019-06-16T18:54:47Z",
"creation_datetime": "2019-06-16T13:24:47.687128Z"
}
],
"total_call_data": [
{
"total_duration": 30,
"user_id": 17,
"call_type": "out_going",
"hour": 3,
"total_calls": 1
},
{
"total_duration": 90,
"user_id": 17,
"call_type": "incoming",
"hour": 4,
"total_calls": 3
},
{
"total_duration": 30,
"user_id": 17,
"call_type": "out_going",
"hour": 4,
"total_calls": 1
},
{
"total_duration": 90,
"user_id": 17,
"call_type": "incoming",
"hour": 5,
"total_calls": 3
},
{
"total_duration": 150,
"user_id": 17,
"call_type": "out_going",
"hour": 5,
"total_calls": 5
},
{
"total_duration": 45,
"user_id": 17,
"call_type": "missed_call",
"hour": 13,
"total_calls": 1
}
]
}
我想用齐射从这个json获取所有请求
最佳答案
您可以使用Gson相当轻松地完成操作,而在这里youtube tutorial
这是一个小代码示例
public void getFromServer(){
final String url =YOUR URL HERE
final ArrayList<ElementEntity> arrayOfCities = new ArrayList<>();
// prepare the Request
final JsonArrayRequest getRequest = new JsonArrayRequest(Request.Method.GET,url,null,
new Response.Listener<JSONArray>()
{
@Override
public void onResponse(JSONArray response) {
// display response
Log.d("Response", response.toString());
for(int i = 0; i< response.length();i++){
try {
JSONObject jresponse = response.getJSONObject(i);
YourObject yourObject = gson.fromJson(jresponse.toString(),YourObject .class);
arrayOfYourObject.add(yourObject);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
},
new Response.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error) {
Log.d("Error.Response", "error");
}
});
// add it to the RequestQueue
queue.add(getRequest);
}
关于java - 如何获得 Volley 的对象,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56621596/