You are doing it wrong. You have filled your JSON Data in your Dictionary (named json
) correctly. But then you have an Array of Dictionaries
(called Albumvideo
) inside your Main Dictionary
and value of titre
is inside Albumvideo
Array.
The Correct Code is :
NSError* error;
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
NSArray* albumsvideo = [json objectForKey:@"Albumvideo"];
NSString *titre1 = [[albumsvideo objectAtIndex:0]valueForKey:@"titre"];
NSString *titre2 = [[albumsvideo objectAtIndex:1]valueForKey:@"titre"];
Understand the Concept. It depends on what you have inside your JSON
. If it's an Array ( Values inside [ ]
) then you have to save in NSArray
, if it's a Dictionary ( Values inside { }
) then save as NSDictionary
and if you have single values like string , integer, double then you have to save them using appropriate Objective-C Data types.
Hope, you got some proper idea about JSON Parsing.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…