0

I'm trying to parse data from my api.My code is correct.I used it a lot of time.But I didn't get any error like this.What I am doing wrong.Can you help me ?

-(void)getStatu {
    NSURL *urlPath = [NSURL URLWithString:@"http://myurl.com/m/cc/cc_today.php"];
    NSData *jsonData = [NSData dataWithContentsOfURL:urlPath];
    NSError *error = nil;
    NSDictionary *dataDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
    NSLog(@"%@",dataDictionary);
    _ccStatus = [NSMutableArray array];
    NSArray *statuArray = [dataDictionary objectEnumerator];
    for (NSDictionary *statuDictionary in statuArray) {
        CCStatu *status = [CCStatu statuWithTitle:[statuDictionary objectForKey:@"gelen"]];
        status.cevap = [statuDictionary objectForKey:@"cevap"];
        status.cort = [statuDictionary valueForKeyPath:@"cort"];
        status.kayip = [statuDictionary valueForKeyPath:@"kayip"];
        status.lort = [statuDictionary valueForKeyPath:@"lort"];
        status.tekil = [statuDictionary valueForKey:@"tekil"];
        [_ccStatus addObject:status];
    }

}

This is my json

2015-08-13 23:54:41.362 CSGB[3215:209292] {
    cevap = "37,627";
    cort = "00:00:48";
    gelen = "54,247";
    kayip = "16,620";
    lort = "00:01:17";
    sl = "46.30 %";
    tekil = "3,316";
}

And this is error

2015-08-13 23:54:58.330 APP[3215:209292] -[__NSCFString objectForKey:]: unrecognized selector sent to instance 0x7fcc12451c30
2015-08-13 23:54:58.336 APP[3215:209292] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectForKey:]: unrecognized selector sent to instance 0x7fcc12451c30'

1 Answer 1

1

Your code is iterating the data incorrectly. You only have a single dictionary. There's nothing to iterate.

NSDictionary *dataDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
NSLog(@"%@",dataDictionary);
_ccStatus = [NSMutableArray array];
CCStatus *status = [CCStatu statuWithTitle:dataDictionary[@"gelen"]];
status.cevap = dataDictionary[@"cevap"];
status.cort = dataDictionary[@"cort"];
status.kayip = dataDictionary[@"kayip"];
status.lort = dataDictionary[@"lort"];
status.tekil = dataDictionary[@"tekil"];
[_ccStatus addObject:status];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.