SBJsonParser *parser = [[SBJsonParser alloc] init];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.krsconnect.no/community/api.html?method=bareListEventsByCategory&appid=620&category-selected=350&counties-selected=Vest-Agder,Aust-Agder"]];
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *json_string = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
NSDictionary *object = [parser objectWithString:json_string error:nil];
NSArray *results = [parser objectWithString:json_string error:nil];
NSDictionary *dictOne = [results objectAtIndex:0];
appDelegate.books = [[NSMutableArray alloc] init];
NSArray *activitiesArray = [dictOne objectForKey:@"events"];
NSDictionary *dictTwo = [activitiesArray objectAtIndex:0];
NSArray *eventArray=[dictTwo objectForKey:@"event"];
NSDictionary *dictThree=[eventArray objectAtIndex:0];
// NSLog(@"%@ - %@", [dictOne objectForKey:@"date"]);
// NSLog(@"%@ - %@", [dictTwo objectForKey:@"affectedDate"]);
NSString*date=[dictOne objectForKey:@"date"];
NSLog(@"%@ - %@", [dictTwo objectForKey:@"affectedDate"]);
NSLog(@"%@ - %@", [dictThree objectForKey:@"title"]);
NSLog(@"%@ - %@", [dictThree objectForKey:@"location"]);
NSLog(@"%@ - %@", [dictThree objectForKey:@"municipality"]);
當我的NSLog(職稱)的位置,直轄市它顯示零值解析JSON數據沒有顯示正確的值
JSON:
[
{
"date": 1311552000000,
"events": [
{
"affectedDate": 1311552000000,
"event": {
"appId": 42,
"eventId": 18095,
"location": "Sjølingstad Uldvarefabrik",
"municipality": "Lindesnes",
"title": "Utstillingsåpning - romfisk"
}
},
{
"affectedDate": 1311552000000,
"event": {
"appId": 42,
"eventId": 18095,
"location": "Sjølingstad Uldvarefabrik",
"municipality": "Lindesnes",
"title": "Utstillingsåpning - romfisk"
}
},
{
"affectedDate": 1311580800000,
"event": {
"appId": 620,
"eventId": 19490,
"location": "Høvåg Gjestehus, Vestre Vallesverd, Høvåg",
"municipality": "Lillesand",
"title": "Kunstutstilling på Høvåg Gjestehus"
}
},
...
]
繼普利文答案我已經試過這個代碼,但它仍然是不工作:
NSDictionary *dictOne = [results objectAtIndex:0];
NSArray *activitiesArray = [dictOne objectForKey:@"events"];
NSDictionary *dictTwo = [activitiesArray objectAtIndex:1];
NSArray *eventArray=[dictTwo objectForKey:@"event"];
NSDictionary *dictThree=[eventArray objectAtIndex:2];
PLS,提供json,所以我們知道它的結構。 – Cyprian
http://www.krsconnect.no/community/api.html?method=bareListEventsByCategory&appid=620&category-selected=350&counties-selected=Vest-Agder,Aust-Agder – Ali
這是我正在使用的json數據 – Ali