我有一个奇怪的错误,我无法绕过头脑。 我正在构建一个使用远程JSON API进行通信的应用程序。 我正在使用AFNetworking来执行请求并遇到与序列化响应相关的问题。
当我使用浏览器调用我们的服务器时,我得到了正确的json响应:
{
{
"tip_uuid": "4067d78c-a222-4190-8d5b-a6822a38e5e6",
"deck_uuid": "c3c0854e-1f28-45ea-a643-c253b5c66a45",
"user_uuid": "fb1dff53-b97f-47f3-b4e7-6c2184b85466",
"latitude": "52.66",
"longitude": "4",
"categoryName": "Other",
"imageURL": "\/images\/dummy_300.png",
"averageRating": 3,
"distanceToLocation": "7596772",
"isUserAwesome": true
},
..... (100 more responses)
}
但是当我使用AFNetworking进行同样的呼叫时
[编辑]
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
[manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"ACCEPT"];
[manager POST:URLString parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
[self processServerResponse:responseObject successBlock:success failureBlock:failure];
}failure:^(AFHTTPRequestOperation *operation, NSError *error) {
DLog(@"------- Failed url: %@ AFNetworking operation: %@. Responsestring: %@", URLString, [error description], operation.responseString);
showM2(NSLocalizedString(@"Network error", @"Network error title"), NSLocalizedString(@"Please try again later", @"network error message"));
failure(nil);
}];
我收到回复: [/编辑]
{
{
averageRating = 0;
categoryName = Music;
"deck_uuid" = "c3c0854e-1f28-45ea-a643-c253b5c66a45";
distanceToLocation = 5718;
imageURL = "/images/tip/fb1dff53-b97f-47f3-b4e7-6c2184b85466_4dd49562817bc39f7567321c22469e7bf846f902_1389202937.png";
isUserAwesome = 0;
latitude = "52.3664193";
longitude = "4.8871613";
"tip_uuid" = "83d5a3f7-be60-4974-9347-67cadc307790";
"user_uuid" = "fb1dff53-b97f-47f3-b4e7-6c2184b85466";
},
....(100 more responses)
}
(最大的)问题是它以某种方式在几个键附近添加引号(tip_uuid,user_uuid和deck_uuid)
为什么如何解决?
答案 0 :(得分:3)
您正在看到JDS和NSDictionary的NSLog之间的区别。 NSDictionary日志仅引用其中包含“特殊”字符的键,而JSON引用所有内容。同样,正斜杠在JSON中转义但在NSDictionary日志中没有转义。没有什么不对,所以没有什么可以解决的。