我从API接收此JSON:
{"MatchedResult":{"CurrentStatus":47}}
使用此代码:
NSString *responseString = [request responseString];
NSDictionary *responseDict = [responseString JSONValue];
NSString *currentStatus = [responseDict objectForKey:@"CurrentStatus"];
返回Null。
使用此代码:
NSString *responseString = [request responseString];
NSDictionary *responseDict = [responseString JSONValue];
NSString *currentStatus = [responseDict objectForKey:@"MatchedResult"];
返回:
{
CurrentStatus = 47;
}
我如何才能获得47的状态?
答案 0 :(得分:0)
你需要深入了解结构:
NSString *responseString = [request responseString];
NSDictionary *responseDict = [responseString JSONValue];
NSString *currentStatus = responseDict[@"MatchedResult"][@"CurrentStatus"];
答案 1 :(得分:0)
您的Response
字典包含Matched Result
字典,其中包含您的CurrentStatus
。
你想......
NSDictionary *matchedResultDict = [responseDict objectForKey:@"MatchedResult"];
NSString *currentStatus = [matchedResultDict objectForKey:@"CurrentStatus"];
答案 2 :(得分:0)
获取您需要的值,您必须分析json以获得必要的密钥
{
"MatchedResult": {
"CurrentStatus": 47
}
}
因为需要CurrentStatus键必须通过MatchedResult
NSString *responseString = [request responseString];
NSDictionary *responseDict = [responseString JSONValue];
NSString *currentStatus = [[responseDict objectForKey:@"MatchedResult"] objectForKey:@"CurrentStatus"];