gpt4 book ai didi

ios - 内容类型 JSON SIGABRT 错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:45:06 27 4
gpt4 key购买 nike

我正在尝试解析 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];

我应该怎么做才能设置内容类型?

最佳答案

您遇到错误是因为您使用的是 Key Value Coding尝试根据请求设置名为 Content-Type 的属性的方法。你也不能修改 NSURLRequest 因为它是不可变的。使用 NSMutableURLRequest相反,然后调用 - (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"];

关于ios - 内容类型 JSON SIGABRT 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14861584/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com