我试图弄清楚我的应用程序发送到我的 Web API 的 JSON 有什么问题,因为它每次发送消息时都会通过命令的“失败”块。但是,当我尝试在本地测试 Web API 时,它确实可以工作并且确实会发布,所以我猜测在创建消息时发送的 JSON 有问题。这是我的代码:
+ (NSArray *)getKeysFighterVM{
NSMutableArray *keys = [[NSMutableArray alloc] initWithObjects:@"Id",
@"EventId",
@"RegistrationId",
@"FirstName",
@"LastName", nil];
return keys;
}
-(void)checkInFighterWCFToBracketId:(NSNumber *)bracketId :(void(^)(bool success, NSError *error, id JSON)) block{
NSArray *requestKeys = [Fighter getWCFKeysFighterVM];
NSArray *requestValues = [NSArray arrayWithObjects:
[NSString stringWithFormat:@"%@", [self.Id stringValue]],
[NSString stringWithFormat:@"%@", [self.eventId stringValue]],
[NSString stringWithFormat:@"%@", [self.regId stringValue]],
[NSNull null],
[NSNull null],
nil];
NSDictionary *jsonRequestDictionary = [NSDictionary dictionaryWithObjects:requestValues forKeys:requestKeys];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"THISWHEREMYAPIURLRESIDES"];
AFHTTPClient *httpclient = [[AFHTTPClient alloc] initWithBaseURL:url];
httpclient.parameterEncoding = AFJSONParameterEncoding;
NSMutableURLRequest *request = [httpclient requestWithMethod:@"POST" path:@"" parameters:jsonRequestDictionary];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSLog(@"SUCCESS JSON %@", JSON);
block(YES, nil, JSON);
}failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON){
JSON = [request HTTPBody];
NSDictionary *jsonDict = (NSDictionary *)JSON;
NSLog(@"FAILURE ERROR JSON %@", jsonDict);
NSArray *jsonarray = (NSArray *)JSON;
NSLog(@"----FAILURE ERROR array %@", jsonarray);
NSLog(@"FAILURE ERROR USErInfo %@", [error userInfo]);
block(NO, error, JSON);
}];
[operation start];
[operation waitUntilFinished];
}
所以我尝试返回它的样子,但返回如下:
----FAILURE ERROR array <7b225573 65724964 223a2238 222c2242 69727468 44617465 223a6e75 6c6c2c22 41636164 656d794e 616d6522 3a6e756c 6c2c2246 69727374 4e616d65 223a6e75 6c6c2c22 4c617374 4e616d65 223a6e75 6c6c2c22 4576656e 74496422 3a223522 2c224576 656e7446 69676874 65725265 67697374 72617469 6f6e4964 223a2235 227d>