Soru & Cevap

NSjsonserialization sorunu

30.06.2014 - 03:38

 

Merhabalar,

Nsjsonserialization kullanarak yaptim ama simulator label icinde herhangi bir data gelmiyor .Consol ekraninda api ciktisi aliyorum ama simulatorde data gelmiyor . nedeni ne olabilir

 

 

 

[code]

- (void)viewDidLoad

{

    [super viewDidLoad];

 

    NSURL *JSONFeed= [NSURL URLWithString:@"http://marsweather.ingenology.com/v1/latest/"];

    NSError * error = nil;

    

    NSData * JSONData =[NSData dataWithContentsOfURL:JSONFeed options:NSDataReadingUncached error:&error];

    

    id jsonObject= [NSJSONSerialization JSONObjectWithData:JSONData options:kNilOptions error:&error];

    

    if (jsonObject !=nil && error==nil) {

        NSLog(@"Success");

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

            NSDictionary * dics= (NSDictionary*)jsonObject; NSLog(@"disc JSON Dictionary =%@",dics);

            

            for (NSString* dataType in dics) {

                if ([dataType isEqualToString:@"json"]) {

                    NSDictionary * content = [dics objectForKey:dataType];

                    

                    for (NSDictionary* data in content) {

                        NSDictionary * detailContent = [data objectForKey:@"report"];

                        NSString * date= [detailContent objectForKey:@"Terrestrial_date"];

                        //NSNumber * sola =[detailContent objectForKey:@"sol"];

                        //NSNumber * lss =[detailContent objectForKey:@"ls"];

                        //NSNumber * minTemp = [detailContent objectForKey:@"min_temp"];

                        //NSNumber * minTempFah= [detailContent objectForKey:@"min_temp_fahrenheit"];

                        //NSNumber * maxTemp =[detailContent objectForKey:@"max_temp"];

                        //NSNumber * maxTempFah =[detailContent objectForKey:@"max_temp_fahrenheit"];

                        NSString *atmo = [detailContent objectForKey:@"atmo_opacity"];

                        wweather.text=[NSString stringWithFormat:date,atmo];

                        

                    }

                }

            }

            

        }

    

        else if ([jsonObject isKindOfClass:[NSArray class]]){

            NSArray * arrray = (NSArray*)jsonObject;NSLog(@"JSon Array =%@",arrray);

            

        }

    

    }

    

    else if (error !=nil){

        NSLog(@"an error");

    }

    

}

 

[/code]

7 Görüntülenme

1 Cevap

Sitedeki sorulara cevap verebilmek için giriş yapın ya da üye olun.

picture-11052-1576825910.jpg
alikarakoc
02.07.2014 - 08:19

[code]- (void)viewDidLoad

{

 

    [super viewDidLoad];

    NSURL *JSONFeed= [NSURL URLWithString:@"http://marsweather.ingenology.com/v1/latest/"];

    NSError * error = nil;

    NSData * JSONData =[NSData dataWithContentsOfURL:JSONFeed options:NSDataReadingUncached error:&error];

    id jsonObject= [NSJSONSerialization JSONObjectWithData:JSONData options:kNilOptions error:&error];

    if (jsonObject !=nil && error==nil) {

        NSLog(@"Success");

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

            NSDictionary * dics= (NSDictionary*)jsonObject;

            NSLog(@"disc JSON Dictionary =%@",dics);

            NSDictionary * detailContent = [dics objectForKey:@"report"];

            NSString * date= [detailContent objectForKey:@"terrestrial_date"];

            NSString *atmo = [detailContent objectForKey:@"atmo_opacity"];

            wweather.text = [NSString stringWithFormat:@"%@ %@",date,atmo];

        }

        else if ([jsonObject isKindOfClass:[NSArray class]]){

            NSArray * arrray = (NSArray*)jsonObject;NSLog(@"JSon Array =%@",arrray);

        }

    }

    else if (error !=nil){

        NSLog(@"an error");

    }

 

}[/code]

 

Şeklinde değiştirirseniz sorun düzelecektir.

server calap
02.07.2014 - 01:18
tesekkurler dostum cok isimi gordun , bakan gozler kor olmus bende....
Ali Karakoç
02.07.2014 - 09:57
rica ederim iyi çalışmalar