Could you please tell me how to pass a JSON String which looks like this:
{"lessons":[{"id":"38","fach":"D","stunde":"t1s1","user_id":"1965","timestamp":"0000-00-00 00:00:00"},{"id":"39","fach":"M","stunde":"t1s2","user_id":"1965","timestamp":"0000-00-00 00:00:00"}]}
I tried it like this:
SBJSON *parser =[[SBJSON alloc] init];
NSArray *list = [[parser objectWithString:JsonData error:nil] copy];
[parser release];
for (NSDictionary *stunden in list)
{
NSString *content = [[stunden objectForKey:@"lessons"] objectForKey:@"stunde"];
}
thanks in advance
best regards
Note that your JSON data has the following structure:
The corresponding code is:
A couple of observations:
In
-objectWithString:error:, theerrorparameter is a pointer to a pointer. It’s more common to useNULLinstead ofnilin that case. It’s also a good idea not to passNULLand use anNSErrorobject to inspect the error in case the method returnsnilIf
jsonObjectis used only in that particular method, you probably don’t need to copy it. The code above doesn’t.