【发布时间】:2018-03-09 03:10:10
【问题描述】:
我正在尝试使用 Objective-C 解析一个简单的 JSON。 我的 JSON 文件如下所示:
{ "videosource": "hello my value" }
还有我的 iOS Objective-C 代码:
NSError *error;
NSString *url_string = [NSString stringWithFormat: @"http://www.mywebsite.com/test"];
NSData *data = [NSData dataWithContentsOfURL: [NSURL URLWithString:url_string]];
NSMutableArray *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSLog(@"my -> json: %@", json);
//NSString *str = json[0]; //<- this one doest not work it makes app crush
//__NSSingleEntryDictionaryI objectAtIndexedSubscript:]: unrecognized selector sent to instance
//NSUInteger num = 0;
//NSString *str = [json objectAtIndex:num]; <- this one doest not work it makes app crush
我正在尝试从 JSON 的 videosource 键中获取值。怎么做?
【问题讨论】:
标签: ios objective-c json