-4

数据 :

2 =     {
        "delivery_cost" = "Free Delivery";
        "delivery_cost_aed" = "0 DHs";
        "delivery_time" = "24 hours";
        "payment_modes" = "[{\"icon\":\"216.70.96.219\\/_media\\/images\\/ico\\/ico_pm_cod.gif\",\"label\":\"Cash On Delivery\"},{\"icon\":\"216.70.96.219\\/_media\\/images\\/ico\\/ico_pm_cod.gif\",\"label\":\"Cash On Delivery\"}]";
        "product_price" = "1,400 DHs";
        "product_url" = "http://www.mygsm.me/Htc-Flyer-16GB.html";
        "shop_id" = "o2md-0qwq-9qam-y5m1";
        "shop_logo" = "216.70.96.219/_media/images/shop_logos/ShopLogos_07.gif";
        "shop_url" = "mygsm.me";
        shopname = "Mygsm.me";
        stock = 1;
        "total_cost" = "1,400 DHs";
        warranty = "216.70.96.219/_media/images/ico/warranty/1.png";
    };

获取价值:

我想从数组中的payment_modes中获取所有图标 url 。像这样

216.70.96.219\/_media\/images\/ico\/ico_pm_cod.gif

216.70.96.219\/_media\/images\/ico\/ico_pm_cod.gif

4

2 回答 2

1

您想要获取 NSJSONSerialization 类。您的代码将如下所示:

    NSDictionary* json = [NSJSONSerialization
                          JSONObjectWithData:responseData
                          options:kNilOptions
                          error:&error];

    NSArray* commands = [json objectForKey:@"foo"];

请注意,我的 JSON 中有一个数组,但它很容易成为字典。

于 2013-07-13T10:37:49.373 回答
0

将 json 字符串转换为 Foundation 对象

NSString *jsonString = ...;
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:jsonString options:0 error:nil];
NSArray *payment_modes = [dict objectForKey:@"payment_modes"];
于 2013-07-13T10:40:16.623 回答