我遇到了这个代码的问题,我无法判断它是JSON还是产生问题的代码。所有参数都是NSLogged,它们是有效的。在服务器端,我们的开发人员说请求成功并在答案中发送JSON。在应用程序方面,JSON生成了一个失败(它是我使用的所有json中的唯一一个,即Weather API,GoogleAPI和内部web服务)。
这是我得到的错误:
AFNETWorking :( Cocoa error 3840.)(JSON文本没有以数组开头 或者允许片段未设置的对象和选项。) NSDebugDescription = JSON文本不是以数组或对象开头的 允许片段未设置的选项。}
代码:
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html", @"application/json", nil];
[manager POST:API_Upload parameters: @{@"firstName": [[Constante picture]hostName],
@"udid":[[Constante picture]hostUDID],
@"ip":[[Constante picture]hostIpAddress],
@"modele":[[Constante picture]hostDevice],
@"latitude":[NSString stringWithFormat:@"%0.2f",[[Constante picture]hostLatitude]],
@"longitude":[NSString stringWithFormat:@"%0.2f",[[ Constante picture]hostLongitude]] ,
@"temperature": [[ Constante picture]hostTemperature],
@"zip": [[ Constante picture]hostZip ],
@"city": [[ Constante picture]hostCity ],
@"country": [[ Constante picture]hostISO],
@"langue":SYSTEM_LANG
} constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
// Add picture to the form
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"phototest" ofType:@"jpg"];
NSURL *filePathUrl = [NSURL fileURLWithPath:filePath];
//NSData *filePathUrl = [NSData dataWithContentsOfFile:filePath];
NSLog(@"file path = %@",filePath);
[formData appendPartWithFileURL:filePathUrl name:@"picture" error:nil];
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Success: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
有关原因的任何线索?