我正在为我的同步请求获取服务器响应和解析,如下所示。
NSDictionary *responseDict = [NSJSONSerialization JSONObjectWithData:response options:0 error:&jsonError];
NSLog(@"responseDict: %@", responseDict);
结果如下:
responseDict: {
d = {
Datavalue = 1;
"__type" = "Response:#DummyAPI";
response = OK;
};
我正在尝试解析上述结果,如果它是“OK”,那么我想将“Datavalue”存储在某处。我正在尝试如下所示,
-(void) handleResponse :(NSDictionary *) responsedata // it is being passed from caller
{
NSString* value = NULL;
for (id key in responsedata)
{
value = (NSString*)[responsedata objectForKey:@"response"];
if ( [value isEqualToString:@"OK"] )
{
NSLog(@"RESPONSE SUCCESS, need to store data value");
}
else
{
NSLog(@"INVALID RESPONSE");
}
}
}
但是,它总是打印“INVALID RESPONSE”,但我得到的响应是“OK”。我在这里做错了什么?请指教!
谢谢!