2011-08-17 7 views
0

このリンクからJSONデータを取得しています。JSONデータを解析するとエラーが発生する

http://www.krsconnect.no/community/api.html?method=event&appid=620&eventid=15946&affecteddate=1310515200000

は私がaDetailDetailクラスのオブジェクトが、その与え、エラーに画像媒体タイトルなどのように、すべての必要なelemntsを保存したいです。あなたがSBJSonを使用する方法はありません

SBJsonParser *parser = [[SBJsonParser alloc] init]; 
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.krsconnect.no/community/api.html?method=event&appid=620&eventid=15946&affecteddate=1310515200000"]]; 


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


for (int i=0; i<[results count]; i++) { 

    NSDictionary*dictOne=[results objectAtIndex:i]; 
    Detail *aDetail = [[Detail alloc] initWithDictionary:[results objectAtIndex:i]];  

    [appDelegate.descriptionArray addObject:aDetail]; 

    } 
+1

を私はあなたがそれらを呼び出しから返されたエラーを無視している3つのメソッドをcount'tすることができ、あなたのエラー –

+2

を投稿してください。物事が失敗し始めて、あなたはただのエラーを無視するだけで、よく.... –

答えて

1

は、ここに私のコードです。このお試しください:

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.krsconnect.no/community/api.html?method=event&appid=620&eventid=15946&affecteddate=1310515200000"]]; 


    NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; 
    NSString *json_string = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]; 
    NSDictionary *object = [json_string JSONValue]; 
0
NSString *json_string = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]; 

NSError *error; 

SBJSON *json = [[SBJSON new] autorelease]; 

id obj = [json objectWithString:json_string error:&error]; 

if ([obj isKindOfClass:[NSDictionary class]]) { 

      [appDelegate.descriptionArray addObject:obj]; 

}else if ([obj isKindOfClass:[NSArray class]]) { 

     for (NSDictionary *aDetail in obj) { 

       [appDelegate.descriptionArray addObject:aDetail]; 

     } 
}