我是这种编码语言的新手,Json 解析故障排除



我学习了一些课程,到了几乎达到我想要的程度。我将添加下面的代码部分,其中包含需要修复的错误。这可能真的很容易解决,只是我是新手,不知道自己在做什么。错误:Expected method to read dictionary element not found on object of type 'NSMutableArray *'这可能不是最有效的方法,不要使用任何过于复杂的单词或短语来帮助我理解它们。如果有人能修复代码,那将非常有用。谢谢。

NSError *error;
NSString *url_string = [NSString stringWithFormat: @"https://******/latest.json"];
NSData *data = [NSData dataWithContentsOfURL: [NSURL URLWithString:url_string]];
NSMutableArray *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions        error:&error];
NSLog(@"json: %@", json);
NSString *BGmmol = json[@"mmol"]; 

您需要将解析结果存储在字典中:

NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions];

最新更新