我正在尝试在 iOS 中解析以下 JSON 代码。JSON 代码由编号为 0 到 x 的游戏数组组成。我一直在四处寻找,但似乎找不到任何具有这种格式的 JSON 的示例。
{
"command":"show_my_games",
"0":{"gameid":"7","foruserid":"16","againstuserid":"0","casefor":"","caseagainst":"","status":"0","argumentid":"7","againstusername":null,"forusername":"Gem","argument":"argument 1"},
"1":{"gameid":"8","foruserid":"15","againstuserid":"16","casefor":"","caseagainst":"","status":"0","argumentid":"23","againstusername":"Gem","forusername":"Nick","argument":"argument 2"},
"2":{"gameid":"9","foruserid":"18","againstuserid":"16","casefor":"","caseagainst":"","status":"0","argumentid":"26","againstusername":"Gem","forusername":"Nick","argument":"argument 3"}
}
我创建了一个游戏对象,对于 JSON 数组中的每个项目,我想创建一个新的游戏对象,并将其添加到游戏数组中。我在解析 JSON 时遇到问题,我将不胜感激任何帮助或建议。
我尝试使用的代码是
NSMutableDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&err];
for (NSMutableDictionary * gameItem in json) {
Game *obj = [Game new];
obj.GameID=[gameItem objectForKey:@"gameid"];
obj.Argument=[gameItem objectForKey:@"argument"];
obj.CaseFor=[gameItem objectForKey:@"casefor"];
obj.CaseAgainst=[gameItem objectForKey:@"caseagainst"];
obj.CaseForOwner=[gameItem objectForKey:@"forusername"];
obj.CaseAgainstOwner=[gameItem objectForKey:@"againstusername"];
obj.CaseForOwnerID=[gameItem objectForKey:@"foruserid"];
obj.CaseAgainstOwnerID=[gameItem objectForKey:@"againstuserid"];
//add to the players game array
[myGameArray addObject:obj];
}
NSLog(@"array: %@", myGameArray);
当我尝试从 JSON 数组中提取数据时,我收到以下错误。-[__NSCFString objectForKey:]:无法识别的选择器发送到实例 0x1f06f4e0
提前致谢,
缺口