解析数据返回nil

时间:2017-05-05 13:43:22

标签: ios swift swift3

我当前的代码在解析数据的id时返回nil。 “结果”是存储所有数据的字典,“id”是我需要的,我的代码是否正确?有关为何返回nil的任何解决方案?:

let resultDictionary = responceDictionary!["result"] as? [String:Any]
print(resultDictionary)
let orderID = resultDictionary!["id"] as? Int
print(orderID)
let orderIDString = "\(orderID)"
print(orderIDString)

有人可以帮我解决如何解析用户在我的应用中创建订单时生成的数据的ID吗?

我是否以数据中的区域为目标来提取我需要的数据?

数据:

Optional(["status": {
    data =     {
        key = unpaid;
        value = Unpaid;
    };
    value = Unpaid;
}, "ship_to": {
    data =     {
        "address_1" = "123 Sunny Street";
        "address_2" = Sunnycreek;
        city = Sunnyvale;
        company = "";
        country =         {
            data =             {
                code = US;
                name = "United States";
            };
            value = "United States";
        };
        county = California;
        "created_at" = "2017-04-22 19:34:48";
        customer =         {
            data =             {
                "created_at" = "2017-04-22 19:34:48";
                email = "jon.doe@gmail.com";
                "first_name" = Jon;
                group = "<null>";
                id = 1498789797559271902;
                "last_name" = Doe;
                order = "<null>";
                password = "<null>";
                "updated_at" = "2017-04-22 19:34:48";
            };
            value = Jon;
        };
        "first_name" = Jon;
        id = 1498789800293958111;
        instructions = "";
        "last_name" = Doe;
        order = "<null>";
        phone = 6507123124;
        postcode = CA94040;
        "save_as" = "";
        "updated_at" = "2017-04-22 19:34:48";
    };
    value = "";
}, "updated_at": 2017-05-05 13:22:22, "id": 1508024425356722199, "bill_to": {
    data =     {
        "address_1" = "123 Sunny Street";
        "address_2" = Sunnycreek;
        city = Sunnyvale;
        company = "";
        country =         {
            data =             {
                code = US;
                name = "United States";
            };
            value = "United States";
        };
        county = California;
        "created_at" = "2017-04-22 19:34:48";
        customer =         {
            data =             {
                "created_at" = "2017-04-22 19:34:48";
                email = "jon.doe@gmail.com";
                "first_name" = Jon;
                group = "<null>";
                id = 1498789797559271902;
                "last_name" = Doe;
                order = "<null>";
                password = "<null>";
                "updated_at" = "2017-04-22 19:34:48";
            };
            value = Jon;
        };
        "first_name" = Jon;
        id = 1498789800293958111;
        instructions = "";
        "last_name" = Doe;
        order = "<null>";
        phone = 6507123124;
        postcode = CA94040;
        "save_as" = "";
        "updated_at" = "2017-04-22 19:34:48";
    };
    value = "";
}, "gateway": {
    data =     {
        description = "<null>";
        enabled = 1;
        name = Dummy;
        slug = dummy;
    };
    value = Dummy;
}, "totals": {
    "shipping_price" =     {
        formatted = "\U00a34.79";
        raw = "4.788";
        rounded = "4.79";
    };
    subtotal =     {
        formatted = "\U00a35,500.00";
        raw = 5500;
        rounded = 5500;
    };
    tax =     {
        formatted = "\U00a31,100.00";
        raw = 1100;
        rounded = 1100;
    };
    total =     {
        formatted = "\U00a36,604.79";
        raw = "6604.79";
        rounded = "6604.79";
    };
}, "created_at": 2017-05-05 13:22:22, "currency": {
    data =     {
        code = GBP;
        "created_at" = "<null>";
        "decimal_point" = ".";
        default = 1;
        enabled = 1;
        "exchange_rate" = 0;
        format = "\U00a3{price}";
        id = 1490649105943233368;
        modifier = "+0";
        rounding = "<null>";
        "thousand_point" = ",";
        title = "British Pound";
        "updated_at" = "<null>";
    };
    value = "British Pound";
}, "shipping": {
    data =     {
        company = "Royal Mail";
        "created_at" = "2017-04-20 16:14:00";
        description = "";
        id = 1497239180449678231;
        order = "<null>";
        price =         {
            data =             {
                formatted =                 {
                    tax = "\U00a30.80";
                    "with_tax" = "\U00a34.79";
                    "without_tax" = "\U00a33.99";
                };
                raw =                 {
                    tax = "0.798";
                    "with_tax" = "4.788";
                    "without_tax" = "3.99";
                };
                rounded =                 {
                    tax = "0.8";
                    "with_tax" = "4.79";
                    "without_tax" = "3.99";
                };
            };
            value = "\U00a34.79";
        };
        "price_max" = 0;
        "price_min" = 0;
        slug = "free-shipping";
        status =         {
            data =             {
                key = 1;
                value = Live;
            };
            value = Live;
        };
        "tax_band" =         {
            data =             {
                "created_at" = "<null>";
                description = "<null>";
                id = 1490649106035507967;
                rate = 20;
                title = Default;
                "updated_at" = "<null>";
            };
            value = Default;
        };
        title = "Standard Shipping";
        "updated_at" = "2017-04-20 16:14:21";
        "weight_max" = 0;
        "weight_min" = 0;
    };
    value = "Standard Shipping";
}, "customer": {
    data =     {
        "created_at" = "2017-04-22 19:34:48";
        email = "jon.doe@gmail.com";
        "first_name" = Jon;
        group = "<null>";
        id = 1498789797559271902;
        "last_name" = Doe;
        order = "<null>";
        password = "<null>";
        "updated_at" = "2017-04-22 19:34:48";
    };
    value = Jon;
}, "order": <null>])

0 个答案:

没有答案