SWIFT:错误域= NSCocoaErrorDomain json解析错误

时间:2016-06-08 11:35:46

标签: ios json swift

你好我有这样的数据来自服务器

{
    "code": 200,
    "msg": [{
        "Trip": {
            "trip_id": "47",
            "user_id": "69",
            "trip_title": "xxx",
            "trip_summary": "Xxxxc",
            "departure_country_id": "233702",
            "arrival_country_id": "233702",
            "departure_date": "2016-05-26 10:29:31",
            "destination_date": "2019-04-26 10:29:31",
            "item_name": "",
            "product_image_path": "app\/webroot\/uploads\/69\/Trip\/571fa5bd2b056test.png",
            "price": "0",
            "fee": "88",
            "trip_post_date": "2016-04-26 05:30:37",
            "active": false
        },
        "User": {
            "user_id": "69",
            "first_name": "jenje",
            "last_name": "nenej",
            "profile_image": "app\/webroot\/uploads\/69\/Profile\/571e69a16592auSSLa.png",
            "country": "Pakistan",
            "phone_no": "00000000"
        },
        "departure_country": {
            "id": "233702",
            "short_country_name": "AD",
            "country_name": "Andorra",
            "state_name": "Andorra la Vella",
            "city_name": "Andorra la Vella"
        },
        "arrival_country": {
            "id": "233702",
            "short_country_name": "AD",
            "country_name": "Andorra",
            "state_name": "Andorra la Vella",
            "city_name": "Andorra la Vella"
        }
    }, {
        "Trip": {
            "trip_id": "46",
            "user_id": "69",
            "trip_title": "vhh",
            "trip_summary": "Bhhh",
            "departure_country_id": "15095",
            "arrival_country_id": "688987",
            "departure_date": "2019-04-26 07:32:36",
            "destination_date": "2019-04-26 07:32:36",
            "item_name": "",
            "product_image_path": "app\/webroot\/uploads\/69\/Trip\/571f7c64df6c7test.png",
            "price": "0",
            "fee": "25",
            "trip_post_date": "2016-04-26 02:34:12",
            "active": false
        },
        "User": {
            "user_id": "69",
            "first_name": "jenje",
            "last_name": "nenej",
            "profile_image": "app\/webroot\/uploads\/69\/Profile\/571e69a16592auSSLa.png",
            "country": "Pakistan",
            "phone_no": "00000000"
        },
        "departure_country": {
            "id": "15095",
            "short_country_name": "AE",
            "country_name": "United Arab Emirates",
            "state_name": "Abu Dhabi",
            "city_name": "Abu Dhabi"
        },
        "arrival_country": {
            "id": "688987",
            "short_country_name": "AD",
            "country_name": "Andorra",
            "state_name": "Encamp",
            "city_name": "Encamp"
        }
    }]
}

我正在使用此代码

let json: NSDictionary?
                do {
                    json = try NSJSONSerialization.JSONObjectWithData(data!, options: .MutableLeaves) as? NSDictionary


                } catch let dataError {
                    // Did the JSONObjectWithData constructor return an error? If so, log the error to the console
                    print(dataError)
}

但它给了我json解析错误。如果您需要整个代码,请告诉我。请帮忙。

错误域= NSCocoaErrorDomain代码= 3840"没有值。" UserInfo = {NSDebugDescription =无值。}

0 个答案:

没有答案