繁体   English   中英

内容类型JSON SIGABRT错误

[英]Content-Type JSON SIGABRT Error

我试图解析JSON,并收到SIGABRT错误: reason: '[<NSURLRequest 0x7e7e970> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key Content-Type.

我的代码是:

self.responseData = [NSMutableData data];
NSURLRequest *request = [NSURLRequest requestWithURL:
                         [NSURL URLWithString:@"http://dmsfw01.dev.com:8082/G.FQI/GVOLFQI.svc/Search(v)?Start=1&Count=10"]];

NSString *contentType = @"application/json";
[request setValue:contentType forKey:@"Content-Type"];

[[NSURLConnection alloc] initWithRequest:request delegate:self];

我应该怎么做才能设置Content-Type?

由于使用的键值编码方法尝试根据请求设置名称为Content-Type的属性,因此出现错误。 另外,您不能修改NSURLRequest因为它是不可变的。 请改用NSMutableURLRequest ,然后为- (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field调用- (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:
                                [NSURL URLWithString:@"http://sw730voldmsfw01.vol1dev.com:8082/GVOL.FQI/GVOLFQI.svc/Search(visa)?Start=1&Count=10"]];

NSString *contentType = @"application/json";
[request setValue:contentType forHTTPHeaderField:@"Content-Type"];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM