我从json dictionory获取字符串,但结果字符串在括号中,我必须得到没有backets的字符串
代码是
jsonDictionary = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
NSDictionary *dictResult = [jsonDictionary objectForKey:@"result"];
NSDictionary *dictPronunciations = [dictResult valueForKey:@"pronunciations"];
NSDictionary *dictAudio = [dictPronunciations valueForKey:@"audio"];
NSString *strMp3Path = [dictAudio valueForKey:@"url"];
NSLog(@"str mp3 path %@",strMp3Path);
,结果是
(
(
"/v2/dictionaries/assets/ldoce/gb_pron/abate0205.mp3"
)
)
我想将/v2/dictionaries/assets/ldoce/gb_pron/abate0205.mp3
作为不带括号的字符串。请帮忙......
答案 0 :(得分:1)
您要记录的对象不是NSString实例。它是数组中数组中的字符串。
尝试:
NSLog(@"str mp3 path %@",strMp3Path[0][0]);
如果按需打印,则对象dictAudio
保持,键url
是一个数组,带有数组。你应该把它固定在字典中。
答案 1 :(得分:0)
尝试使用以下代码:
NSMutableArray *myArray = [dictAudio valueForKey:@"url"];
NSString *myStr = [[myArray objectAtIndex:0] objectAtIndex:0];
NSLog(@"%@", myStr);
答案 2 :(得分:0)
使用此代码。如果您的值是json的倍数,则可以逐个添加值而不使用大括号:
NSMutableArray *dictPronunciations = [dictResult valueForKey:@"pronunciations"];
NSMutableArray *arrayPronunciations = [[NSMutableArray alloc] init];
for (int i = 0; i< [dictPronunciations count]; i++)
{
NSString *string = [dictPronunciations objectAtIndex:i];
NSLog(@"String = %@",string);
[arrayPronunciations addObject:string];
}
NSLog(@"Array Pronounciations = %@",arrayPronunciations);