-1
当我发出post请求并在json中返回null元素时,它被解析为"<null>"
而不是NSNull。Afnetworking不能正确解析null
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSURL * nsurl = [NSURL URLWithString:url relativeToURL:[NSURL URLWithString:self.baseUrl]];
NSMutableURLRequest *request = [manager.requestSerializer requestWithMethod:method URLString:[nsurl absoluteString] parameters:data error:nil];
AFHTTPRequestOperation * operation;
operation = [manager HTTPRequestOperationWithRequest:request
success: ^(AFHTTPRequestOperation *operation , id responseObject){
if([[HEEnv env][@"debugLevel"] intValue]>0){
NSLog(@"JSON: %@", responseObject);
}
[self parseFromJSON:responseObject];
completion(nil);
}
failure: ^(AFHTTPRequestOperation *operation , NSError *error){
NSLog(@"Error: %@", error);
completion(error);
}
];
[manager.operationQueue addOperation:operation];
响应
JSON: {
"created_at" = "2014-02-18T19:58:46.000Z";
id = 1;
"is_new" = 0;
level = "<null>";
"topic_id" = "<null>";
"updated_at" = "2014-02-19T20:09:27.129Z";
xp = "<null>";
}
咦?日志输出显示“”,而不是“@”“'。 –
rmaddy
@rmaddy:这是一个格式问题。如果未引用或转义,则将<<...'解释为HTML命令。 –
@MartinR我刚刚意识到,编辑后。谢谢。 – rmaddy