【问题标题】:I have a code, where json data is retrieved, Now I want handle different exceptions我有一个代码,其中检索 json 数据,现在我想处理不同的异常
【发布时间】:2021-07-27 08:01:00
【问题描述】:

我已经包含了 JsonException。 对于无响应、不同的键或值以及不同的 JSON 结构,我们有什么例外吗? 我在 android 中使用 kotlin。

【问题讨论】:

    标签: android android-studio kotlin


    【解决方案1】:

    JSONException 包括以下情况:

    Attempts to parse or construct malformed documents
    Use of null as a name
    Use of numeric types not available to JSON, such as NaNs or infinities.
    Lookups using an out of range index or nonexistent name
    Type mismatches on lookups
    

    如果您从网络获取 JSON,您应该处理其他异常,例如 IOException。这与 JSON 无关,也不包含在 JSONException 中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-19
      • 1970-01-01
      • 2013-07-08
      • 1970-01-01
      • 1970-01-01
      • 2021-10-09
      • 1970-01-01
      相关资源
      最近更新 更多