【问题标题】:How can I check the null response from url如何检查来自 url 的空响应
【发布时间】:2019-07-11 16:07:23
【问题描述】:

这是我在检查数组响应是否为空时从我的 url 得到的响应,它显示错误

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

【问题讨论】:

    标签: android json android-volley


    【解决方案1】:

    org.json.JSONException: 值

    ...

    org.json.JSONArray 类型无法转换为 JSONObject

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

    [
      {},
      {},
      {},
    ]
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-01
      • 2011-10-05
      • 2012-05-11
      • 1970-01-01
      相关资源
      最近更新 更多