响应:
{
"AT": null,
"EMs": [
{
"EC": null,
"LM": null,
"SCs": 0,
"SM": "Username or Password is invalid."
}
],
"OS": 1,
"PWD": "3456",
"UId": 399,
"UN": "bb",
"COM": "Apple",
"DId": 0,
"DN": "iPhone",
"DOS": "iOS",
"EA": "aa@gmail.com",
"FN": "bb",
"IsCon": true,
"IsSuc": false,
"SD": "bb",
"SLT": "XU0QpDVC",
"STs": 0,
"UQId": "1d3346c",
"US": 2,
"Ver": "6.0"
}
这里我想获取“用户名或密码无效”之类的 SM 标签值。
我试过这段代码
NSError *error;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
NSString *SMString = [json objectForKey:@"SM"];
NSString *OSString = [json objectForKey:@"OS"];
NSString *DIdString = [json objectForKey:@"DId"];
NSString *UIdString = [json objectForKey:@"UId"];
最佳答案
我希望它能工作:
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData
options:kNilOptions
error:&error];
NSArray *EMsArray = [json objectForKey:@"EMs"];
NSAssert([EMsArray count] > 0, @"Expected at least one element in EMs array");
NSString *SMString = [[EMsArray objectAtIndex:0] objectForKey:@"SM"];
关于iphone - 如何获取 JSON 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16649005/