【发布时间】:2014-07-25 12:28:42
【问题描述】:
我尝试在 iOS 中解析 json,但出现错误。 这是我从 api 得到的 json
data = (
{
LogIn = {
Emails = "abc@xyz`.com";
Latitude = "37.33233141";
Longitude = "-122.03121860";
Password = 123456;
};
Status = Success;
}
);
我想要所有详细信息,例如电子邮件、纬度、经度和密码以及状态。我正在尝试下面的 json 代码
loginurl= [NSURL URLWithString:string1];
NSLog(@"url is %@",string1);
dispatch_async(kBgQueue, ^{
NSData *data = [NSData dataWithContentsOfURL:loginurl];
[self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];
});
这是我的获取数据方法 -
-(void)fetchedData:(NSData *)responseData
{
NSError * error;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
NSLog(@"JSON: %@", json);
NSDictionary *data = [json objectForKey:@"data"];
NSArray *currentConditions = [data objectForKey:@"LogIn"];
NSDictionary *conditions = [currentConditions objectAtIndex:0];
NSLog(@"%@",conditions);
}
【问题讨论】: