NSJSONSerialization提供nil对象

时间:2017-01-13 10:24:09

标签: objective-c nsdata nsjsonserialization

我正在尝试发送POST请求,如下所示:

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",BASE_URL,jobListURL]];

NSError *error;

NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
                                                       cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                   timeoutInterval:60.0];

[request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request addValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setHTTPMethod:@"POST"];

NSDictionary *mapData = [[NSDictionary alloc] initWithObjectsAndKeys:poID, @"purchaseorderid",nil];
NSLog(@"map data %@",mapData);
NSData *postData = [NSJSONSerialization dataWithJSONObject:mapData options:0 error:&error];
[request setHTTPBody:postData];

NSURLSessionDataTask *postDataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {

    NSLog(@"NSURLResponse : %@",response);
    NSDictionary *responseDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];

    NSLog(@"responseDict Object : %@",responseDict); //provides -->(null)

}];

[postDataTask resume];

这里响应的NSData *数据看起来像这样:

<OS_dispatch_data: data[0x7fc10dd2e6e0] = { composite, size = 22057, num_records = 14 , flatbuf = 0x7fc11085ba00 record[0] = { from = 0, length = 1266, data_object = 0x60800027b280 }, record[1] = { from = 0, length = 1448, data_object = 0x60800027afc0 }, record[2] = { from = 0, length = 1448, data_object = 0x60800027b680 }, record[3] = { from = 0, length = 1448, data_object = 0x60000027cb40 }, record[4] = { from = 0, length = 1448, data_object = 0x60800027b700 }, record[5] = { from = 0, length = 1448, data_object = 0x60000027d040 }, record[6] = { from = 0, length = 1448, data_object = 0x60800027b100 }, record[7] = { from = 0, length = 1448, data_object = 0x60000027cf00 }, record[8] = { from = 0, length = 1448, data_object = 0x60000027d340 }, record[9] = { from = 0, length = 1448, data_object = 0x60800027af00 }, record[10] = { from = 0, length = 1448, data_object = 0x60000027d2c0 }, record[11] = { from = 0, length = 2072, data_object = 0x60800027ae40 }, record[12] = { from = 0, length = 2896, data_object = 0x60000027d780 }, record[13] = { from = 0, length = 1343, data_object = 0x60000027d840 }, }>

这可能是什么问题?有什么想法吗?

0 个答案:

没有答案