-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