快速输入字符0周围的无效值

时间:2019-02-25 06:35:51

标签: ios json swift api jsonparser

我正在开发一个iOS应用程序,其中它使用API​​来获取用户信息。这是我从服务器返回的响应,该服务器是JSON对象:

    {
    "status": {
        "code": 200,
        "message": "OK",
        "error": 0,
        "error_messages": []
    },
    "data": {
        "id": 1111,
        "name": "xxxxxxxx",
        "triple_name": "xxxxxxxx",
        "english_name": "xxxxxxxx",
        "email": "xxxxxxxx",
        "telephone": "xxxxxxxx",
        "username": "xxxxxxxx",
        "id_type": "xxxxxxxx",
        "id_number": "xxxxxxxx",
        "id_expiry_date": null,
        "id_photo": null,
        "gender": "xxxxxxxx",
        "date_of_birth": "xxxxxxxx",
        "h_date_of_birth": null,
        "nationality_id": 0,
        "country_id": 0,
        "city_id": 0,
        "degree_id": null,
        "personal_photo": null,
        "is_government_employee": 0,
        "iban": null,
        "bank_id": null,
        "access_token": "xxxxxxxx",
        "country_name": "xxxxxxxx",
        "city_name": "xxxxxxxx"
    }
}

但是,此行代码出现错误:

let myJSON = try JSONSerialization.jsonObject(with: data!, options: .allowFragments) as? NSDictionary

错误是:

  

字符0周围的无效值

。我使用了JSON验证程序,它说JSON有效。但是,我不断收到此错误

1 个答案:

答案 0 :(得分:0)

尝试将NSDictonary更改为[String:AnyObject] 或[String:Any]