0

我有以下 Json 作为

{
"meta": {
    "code": 200
       }, 
"response": {
           "deals": [           {
                "id": 32373, 
            "date_added": "2011-01-13 12:12:50", 
            "end_date": "2011-01-14 10:00:00", 
            "active": 1, 
            "discount": {
                "raw": 71, 
                "formatted": "71%"
            }, 
            "price": {
                "raw": "85.00", 
                "formatted": "$85"
            }, 
            "value": {
                "raw": "300.00", 
                "formatted": "$300"
            }, 
            "purchased": 82, 
            "left": null, 
            "title": "$85 For $300 Babyface Facial At Park Avenue MedSpa", 
            "yipit_title": "71% off Babyface Facial", 
            "url": "http://yipit.com/aff/click/?deal=AvwTADtE&key=F374EFbM", 
            "yipit_url": "http://yipit.com/new-york/livingsocial/85-for-300-babyface-facial-at-park-avenue-medspa/", 
            "images": {
                "image_big": "http://d22nv2k05ynu7x.cloudfront.net/deal_images/deal/85-for-300-babyface-facial-at-park-avenue-medspa-1294920769_display_image.jpg", 
                "image_small": "http://d22nv2k05ynu7x.cloudfront.net/deal_images/deal/85-for-300-babyface-facial-at-park-avenue-medspa-1294920769_small_image.jpg"
            }, 
            "division": {
                "slug": "new-york", 
                "name": "New York", 
                "active": 1, 
                "time_zone_diff": -4, 
                "lat": "40.7142690000000000", 
                "lon": "-74.0059730000000000", 
                "url": "http://yipit.com/new-york/"
            }, 
            "tags": [
                {
                    "name": "Facial", 
                    "slug": "facial", 
                    "url": "http://yipit.com/new-york/deals/facial/"
                }, 
                {
                    "name": "Spa", 
                    "slug": "spa", 
                    "url": "http://yipit.com/new-york/deals/spa/"
                }
            ], 
            "business": {
                "name": "Park Avenue MedSpa", 
                "url": "", 
                "locations": [
                    {
                        "address": "565 Park Ave", 
                       "locality": "New York",
                        "phone": "212-593-8821", 
                        "lat": null, 
                        "lon": null
                    }
                ]
            }, 
            "source": {
                "name": "LivingSocial", 
                "slug": "livingsocial", 
                "paid": 0, 
                "url": "http://yipit.com/new-york/livingsocial"
            }
        }
    ]
}
    }

我正在使用 NSJSONSerialization 解析这个 json 看起来像我的代码

 NSError *jsonError;
NSMutableDictionary *jsonDictionary = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&jsonError];
NSMutableArray *resultArray = [[jsonDictionary objectForKey:@"response"] valueForKeyPath:@"deals.business.locations"];
self.tempArray = [[NSMutableArray alloc]init];
aData = [[Data alloc]initwithName:[[resultArray objectAtIndex:0]valueForKey:@"address"]];
[self.tempArray addObject:aData];

但我的地址值显示为带有括号,如 ("565 Park Ave") 但我只想显示 565 Park Ave 值。怎么能解决这个问题。

4

2 回答 2

0

您应该从 JSON aData 创建一个字符串。aData 保留“”,但从数据解码的字符串不会有

于 2012-11-07T14:28:19.580 回答
0

当您NSLog像这样的数组或字典时,它会在长度超过一个单词的字符串周围写入 "。别担心,565 Park Ave即使 NSLog 写入,您的数据也只会是"565 Park Ave".

这是-(NSString*)description在两个容器中处理字符串的方式。

于 2012-11-07T13:38:09.343 回答