0

データを解析していますが、辞書内のすべてのデータを取得していますが、NSLog を使用して値を確認すると、nil 値が表示されます

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];
//appDelegate.books = [[NSMutableArray alloc] initWithCapacity:0];

appDelegate.books1 = [[NSMutableArray alloc] init];


NSArray *results = [parser objectWithString:json_string error:nil];
for (int i=0; i<[results count]; i++) {
    Book1  *aBook = [[Book1 alloc] initWithDictionary:[results objectAtIndex:i]];
    [appDelegate.books1 addObject:aBook];
    Book1 *mybook=[appDelegate.books1 objectAtIndex:i];
    NSString*test=mybook.location;
    NSLog(test);
}

辞書解析

 - (id)initWithDictionary:(NSDictionary*) dict {

    self.date = [dict valueForKey:@"date"];
    self.location =  [dict valueForKey:@"location"];
    self.municipality = [dict valueForKey:@"municipality"];
    self.title =  [dict valueForKey:@"title"];

    return self;

 }
4

2 に答える 2

1

あなたの辞書には「場所」が含まれていないと思いますが、それはその Web サイトから戻ってきたものと一致しています。辞書の配列を含む辞書の配列を送り返します。「場所」を見つけるには、これらの内部辞書の 1 つを抽出する必要があります。

[

    {
        "date":1320883200000,
        "events":[
            {
                "affectedDate":1320883200000,
                "event":{
                    "appId":620,
                    "eventId":20672,
                    "location":"Samsen Kulturhus",
                    "municipality":"Kristiansand",
                    "title":"AKKS kurs høsten 2011"
                }
            },
         ....
于 2011-11-09T02:11:03.263 に答える
0

試す:

- (id)initWithDictionary:(NSDictionary*) dict {
   self = [super init];
   if(self) {
      self.date = [dict valueForKey:@"date"];
      self.location =  [dict valueForKey:@"location"];
      self.municipality = [dict valueForKey:@"municipality"];
      self.title =  [dict valueForKey:@"title"];
   }
   return self;
}
于 2012-02-14T11:12:24.647 に答える