我收到以下错误:
com.android.volley.ParseError: org.json.JSONException: End of input at character 0 of
这是我的代码:
public void onResponse(JSONObject response) {
dialog.dismiss();
Log.d("response", response.toString());
JSONArray jsonArray = null;
try {
jsonArray = response.getJSONArray("assignments");
if(jsonArray.length()==0)
{
Toast.makeText(getApplicationContext(), "Assignments Not Found", Toast.LENGTH_LONG).show();
}
CardView cardView=(CardView)findViewById(R.id.list_item5);
cardView.setVisibility(View.VISIBLE);
assignmentModuleListList.clear();
for (int i = 0; i < jsonArray.length(); i++) {
AssignmentModule assignmentModule = new AssignmentModule();
JSONObject jsonObject1 = jsonArray.getJSONObject(i);
assignmentModule.setAssignmentName(jsonObject1.getString("assignmentName"));
assignmentModule.setDescription(jsonObject1.getString("description"));
assignmentModule.setSubjectName(jsonObject1.getString("subjectName"));
String date=jsonObject1.getString("startDate").substring(0,10);
String date1=jsonObject1.getString("endDate").substring(0, 10);
assignmentModule.setAssignDate(date+"\n"+"\t\t\t"+"to"+"\n"+date1);
assignmentModuleListList.add(assignmentModule);
}
setdata(assignmentModuleListList);
dialog.dismiss();
} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_LONG).show();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
dialog.dismiss();
Log.d("error",error.toString());
String timeout=error.toString();
if(timeout.equalsIgnoreCase("com.android.volley.TimeoutError"))
{
Toast.makeText(getApplicationContext(), "Opp's Server Can't Load Please Try Again Latter", Toast.LENGTH_LONG).show();
}
NetworkResponse response = error.networkResponse;
if(response != null && response.data != null){
switch(response.statusCode){
case 400:
Toast.makeText(getApplicationContext(), "400 Error", Toast.LENGTH_LONG).show();
break;
case 404:
Toast.makeText(getApplicationContext(), "Assignments Not Found", Toast.LENGTH_LONG).show();
break;
case 500:
Toast toast1 = Toast.makeText(getApplicationContext(), "Internal Server Error", Toast.LENGTH_SHORT);
TextView v1 = (TextView) toast1.getView().findViewById(android.R.id.message);
v1.setTextColor(Color.RED);
toast1.show();
break;
}
//Additional cases
}
}
这是解析后我所期待的:
{
"assignments":[
{
"assignmentName":"asignment1",
"description":"first poam",
"subjectName":"kannada",
"startDate":"2016-01-22",
"endDate":"2016-01-23"
},
{
"assignmentName":"assigment3",
"description":"thrid lesson",
"subjectName":"kannada",
"startDate":"2016-01-22",
"endDate":"2016-01-23"
}
]
}