【发布时间】:2016-01-30 11:11:43
【问题描述】:
您好,我正在对搜索关键字进行 json 序列化,如果我们没有找到搜索关键字,那么它将返回如下所示的空
{“工作”:[]}
但是我在解析下面是我的代码sn-p时遇到错误
__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];
}
}
现在我得到了休息代码 200,响应为空,错误为
NSCocoaErrorDomain Code=3840 错误“无法执行该操作 完全的。 (Cocoa 错误 3840。)”(字符 0 周围的值无效。)
我想念的地方请任何人帮助我
【问题讨论】:
-
你能把儿子的回复发在这里吗?
-
抱歉我没听明白你的意思是json响应然后它是空的
-
检查什么数据得到,从错误看来是无效的儿子,尽管它的 200 响应代码,
-
为了在控制台中获取响应,在完成处理程序中放置一个断点并在调试器区域输入以下行 [[NSString alloc] initWithData: data encoding:4];
-
我尝试使用你的我们服务,但它得到你的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 22 行的 ') order by jobs.datetime desc' 附近使用正确的语法