检测到不正确的NSStringEncoding值0x0000 [英] Incorrect NSStringEncoding value 0x0000 detected

查看:730
本文介绍了检测到不正确的NSStringEncoding值0x0000的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iphone中使用ASIHttpRequest库,当我尝试在下面的URL上执行GET请求时,我收到此消息并且请求失败,如果他/她遇到此问题或者知道可能的解决方案请其他人请让我知道。其次,如果我在浏览器中粘贴链接,它就可以正常工作。

I am using ASIHttpRequest library in iphone and when i try to do a GET request on the below URL i get this message and the request fails, please anyone if he/she has encountered this problem or know a possible solution to it please let me know. Secondly if i paste the link in the browser it works perfectly fine.

[URL]

http://www.rugsale。 com / iphone / app /?type = product_list& params = id%3D334& ver = 1.0& key = kaoud

[ERROR]

检测到不正确的NSStringEncoding值0x0000。假设NSStringEncodingASCII。将在不久的将来停止这种兼容性映射行为。

Incorrect NSStringEncoding value 0x0000 detected. Assuming NSStringEncodingASCII. Will stop this compatiblity mapping behavior in the near future.

提前Thx

问候

Syed Arsalan Pervez
www.saplogix.net

Syed Arsalan Pervez www.saplogix.net

推荐答案

这显然发生了如果在返回有效响应并且已设置请求编码(即无法连接到服务器)之前调用 [asiHttpRequest getResponseString]

This notably happens if you call [asiHttpRequest getResponseString] before a valid response has been returned and the request encoding has been set (i.e. couldn't connect to server).

解决此警告的最简单方法是编辑 ASIHTTPRequest 类,删除 @synthesize responseEncoding 并添加一个简单的自定义getter / setter,以便在未设置响应编码时返回默认编码:

The easiest way to workaround this warning is by editing the ASIHTTPRequest class, remove the @synthesize responseEncoding and adding a simple custom getter/setter so you can return the default encoding if the response encoding isn't set:

- (NSStringEncoding) responseEncoding
{
    return responseEncoding || self.defaultResponseEncoding;
}

- (void) setResponseEncoding:(NSStringEncoding)_responseEncoding
{
    responseEncoding = _responseEncoding;
}

getResponseString <还有一个更具体的解决方法/ code>方法,我认为这是唯一使用编码而不检查值的地方 - 因为编码应该设置为任何非零长度响应:

There's also a more specific workaround for the getResponseString method, which I think is the only place that uses the encoding without checking for a value - since the encoding should be set for any non-zero length response:

- (NSString *)responseString
{
    NSData *data = [self responseData];
    if (!data) {
        return nil;
    }
    // --- INSERT THIS BLOCK ---
    // If the 'data' is present but empty, return a simple empty string
    if (data.length == 0) {
        return @"";
    }
    //assert(self.responseEncoding); // if you're into runtime asserts, uncomment this
    // --- END OF BLOCK TO INSERT ---
    return [[[NSString alloc] initWithBytes:[data bytes] length:[data length] encoding:[self responseEncoding]] autorelease];
}

这篇关于检测到不正确的NSStringEncoding值0x0000的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆