如何检查网址的空响应

时间:2019-07-11 16:07:23

标签: android json android-volley

这是我的响应,当我检查数组响应是否为空或不是向我显示该错误时,我会从我的网址中获取

org.json.JSONException: Value 

[
  {
    "ReceiverFullName": "",
    "Description": "",
    "DateofAppointment": "/Date(1546322400000)/",
    "SenderFullName": "",
    "Behaviour": null,
    "AppointmentId": 1056,
    "UpdateBy": null,
    "AddDate": "/Date(1562821200000)/",
    "TimeofAppointment": "01:00PM",
    "Title": "",
    "ReceiverBadgeId": 1053,
    "TokenId": "",
    "Status": null,
    "ReceiverUserId": 193,
    "IsNotificationReceived": null,
    "IsNotificationSend": true,
    "UpdateDate": null,
    "SenderUserId": 188
  },
  {
    "ReceiverFullName": "IN",
    "Description": "i want to discuss something with you ",
    "DateofAppointment": "/Date(1570424400000)/",
    "SenderFullName": "MuhammadAbdullah",
    "Behaviour": true,
    "AppointmentId": 1055,
    "UpdateBy": null,
    "AddDate": "/Date(1562734800000)/",
    "TimeofAppointment": "04:00 PM",
    "Title": "hello",
    "ReceiverBadgeId": 330,
    "TokenId": "do8e3lb6fjE:APA91bFXpDpQ-BMg1AMok5RsMIrIodp9fDm30Yswwq08BowRdog8GbjD4apVlhVlTXES5vUZl6fjuNYobDvHhTHr0Aj9jqF-A0J8E64xhxsBXfaky58O6QHuKMipp4RJi2rZP7E4i7Aj",
    "Status": "accepted",
    "ReceiverUserId": 193,
    "IsNotificationReceived": null,
    "IsNotificationSend": true,
    "UpdateDate": null,
    "SenderUserId": 188
  },
  {
    "ReceiverFullName": "IN",
    "Description": "asdasasdasda",
    "DateofAppointment": "/Date(1546322400000)/",
    "SenderFullName": "Muhammad",
    "Behaviour": true,
    "AppointmentId": 1051,
    "UpdateBy": null,
    "AddDate": "/Date(1562648400000)/",
    "TimeofAppointment": "1:02PM",
    "Title": "sadas",
    "ReceiverBadgeId": 330,
    "TokenId": "",
    "Status": "accepted",
    "ReceiverUserId": 193,
    "IsNotificationReceived": null,
    "IsNotificationSend": true,
    "UpdateDate": null,
    "SenderUserId": 188
  },
  {
    "ReceiverFullName": "IN",
    "Description": "i want to meet you",
    "DateofAppointment": "/Date(1567832400000)/",
    "SenderFullName": "MuhammadAbdullah",
    "Behaviour": true,
    "AppointmentId": 1053,
    "UpdateBy": null,
    "AddDate": "/Date(1562648400000)/",
    "TimeofAppointment": "10:00 AM",
    "Title": "Meeting ",
    "ReceiverBadgeId": 330,
    "TokenId": "do8e3lb6fjE:APA91bFXpDpQ-BMg1AMok5RsMIrIodp9fDm30Yswwq08BowRdog8GbjD4apVlhVlTXES5vUZl6fjuNYobDvHhTHr0Aj9jqF-A0J8E64xhxsBXfaky58O6QHuKMipp4RJi2rZP7E4i7Aj",
    "Status": "rejected",
    "ReceiverUserId": 193,
    "IsNotificationReceived": null,
    "IsNotificationSend": true,
    "UpdateDate": null,
    "SenderUserId": 188
  }
]

of type org.json.JSONArray cannot be converted to JSONObject

1 个答案:

答案 0 :(得分:0)

  

org.json.JSONException:值

     

...

     类型为org.json.JSONArray的

无法转换为JSONObject

这是一个预期的错误,因为您的响应是这样的 Array

[
  {},
  {},
  {},
]

因此,您需要将响应作为对象数组而不是对象来处理。有关JSON的更多详细信息,请参见https://www.json.org/