-2

I am getting string from json dictionory but result string is in brackets, i have to get string without backets

code is

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);

and result is

(
    (
        "/v2/dictionaries/assets/ldoce/gb_pron/abate0205.mp3"
    )
)

I want to get /v2/dictionaries/assets/ldoce/gb_pron/abate0205.mp3 as a string without brackets. Please help...

vikingosegundo
  • 52,040
  • 14
  • 137
  • 178
Rajpal Thakur
  • 355
  • 2
  • 15

3 Answers3

1

The object you are logging is not a NSString instance. it is a string inside an array in an array.

try:

NSLog(@"str mp3 path %@",strMp3Path[0][0]);

if this prints as desired, the object dictAudio holds with the key url is an array, with an array. you should fix that where ever you stick it into the dictionary.

vikingosegundo
  • 52,040
  • 14
  • 137
  • 178
0

Try with following code:

NSMutableArray *myArray = [dictAudio valueForKey:@"url"];
NSString *myStr = [[myArray objectAtIndex:0] objectAtIndex:0];
NSLog(@"%@", myStr);
iPatel
  • 46,010
  • 16
  • 115
  • 137
0

Use this code. If your values are multiple from json then the value can be added one by one without braces :

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);
Gurpreet
  • 181
  • 6