ios json序列化NSCocoaErrorDomain代码= 3840错误

时间:2015-10-30 05:03:48

标签: ios iphone json

您好我正在搜索关键字的json序列化,如果我们没有找到搜索关键字,那么它将返回如下所示的空

  

{ “工作”:[]}

但我收到错误,而下面的解析是我的代码片段

__block BOOL userGetJobDataIsReceived = NO;
NSURL *url;
NSData *postData;
 defaults = [NSUserDefaults standardUserDefaults];
 postData =[[[NSString alloc] initWithFormat:@"user_id=%ld&search=%@",(long)userID,self.textField.text]dataUsingEncoding:NSUTF8StringEncoding];
 url=[NSURL URLWithString:@"http://getjoblocation.com/webservices/searchjobs.php?"];

NSLog(@"Search URL => %@%@",url,postData);
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
        [request setURL:url];
        [request setHTTPMethod:@"POST"];
        [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
        [request setHTTPBody:postData];

        NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration ephemeralSessionConfiguration]];
        [[session dataTaskWithRequest:request
                    completionHandler:^(NSData *data, NSURLResponse *response, NSError *requestError) {
                        NSHTTPURLResponse *HTTPResponse = (NSHTTPURLResponse *)response;

                        if (requestError) {
                            NSLog(@"Request error occurred: %@", requestError);
                        }

                        //if communication was successful
                        if ([HTTPResponse statusCode] >= 200 && [HTTPResponse statusCode] < 300) {
                            NSLog(@"status code ::::%ld",(long)[HTTPResponse statusCode]);

                            NSInteger success = 1;
                            NSError *serializeError = nil;
                            NSDictionary *jsonData = [NSJSONSerialization
                                                      JSONObjectWithData:data
                                                      options:NSJSONReadingAllowFragments
                                                      error:&serializeError];
                            success = [jsonData[@"ERROR"] integerValue];
                            if (serializeError) {
                                NSLog(@"JSON serialize error occurred: %@", serializeError);
                            }

                            if (success==0) {

                                userGetJobDataIsReceived = YES;
                                //do stuff with jsonData dictionary here

                                NSLog(@"Search Response: %@ ",jsonData);

                                if([userTypeForGetJOb isEqualToString:@"Worker"]) {

                                    if ((unsigned long)[jobsDetailArray count]==0) {
                                        //if not job
                                        avijitIndexNumberItem=0;
                                        [self.view addSubview:self.SearchContainerView];

                                        // self.searchViewLabel.text=NSLocalizedString(@"No_Job_Found_Tap_pic_LocStr", @"No jobs found please tap profile picture to search again");
                                        self.searchViewLabel.text=NSLocalizedString(@"No_Job_Found_Tap_pic_LocStr", @"Job approval are reviewed by employee, when he accept we will update you.");

                                    }else{
                                        NSLog(@"%s", __PRETTY_FUNCTION__);

                                        [self.SearchContainerView removeFromSuperview];
                                        //cution
                                        avijitIndexNumberItem=0;
                                        [self indexChangedPleaseChangeStuff:0];

                                    }
                                }

现在我得到repose代码200,响应为空,错误是

  

NSCocoaErrorDomain代码= 3840错误“操作无法执行   完成。 (可可错误3840.)“(字符0周围的值无效。)

我想念的任何人请帮助我

1 个答案:

答案 0 :(得分:-1)

NSData *postData;更改为NSMutableData *postData;