Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios NSMutabledata字节容量_Ios_Nsmutabledata - Fatal编程技术网

Ios NSMutabledata字节容量

Ios NSMutabledata字节容量,ios,nsmutabledata,Ios,Nsmutabledata,可能重复: 当我有一个NSMutableData变量时,在我的程序中,当它有90810字节时,它总是转储它的内容。数据中的字节数是否会导致数据丢失? 这是代码 - (void)fetchEntries { // Construct a URL that will ask the service for what you want NSURL *url = [NSURL URLWithString: @"http://www.nhara.org/scored_races

可能重复:

当我有一个NSMutableData变量时,在我的程序中,当它有90810字节时,它总是转储它的内容。数据中的字节数是否会导致数据丢失? 这是代码

- (void)fetchEntries
{
        // Construct a URL that will ask the service for what you want 
    NSURL *url = [NSURL URLWithString: @"http://www.nhara.org/scored_races-2013.htm"];//

    // Put that URL into an NSURLRequest
    NSURLRequest *req = [NSURLRequest requestWithURL:url];

    // Create a connection that will exchange this request for data from the URL 
    connection = [[NSURLConnection alloc] initWithRequest:req delegate:self startImmediately:YES];
}

- (void)connection:(NSURLConnection *)conn didReceiveData:(NSData *)data 
{
    // Add the incoming chunk of data to the container we are keeping 
    // The data always comes in the correct order 
     [xmlData appendData:data];


    NSString *xmlCheck = [[[NSString alloc] initWithData:xmlData encoding:NSUTF8StringEncoding]autorelease];
    NSLog(@"xmlCheck = %@", xmlCheck);

}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
    NSLog(@"error= %@",error);
}

- (void)connectionDidFinishLoading:(NSURLConnection *)conn {

    // We are just checking to make sure we are getting the XML 
    NSString *xmlCheck = [[[NSString alloc] initWithData:xmlData encoding:NSUTF8StringEncoding] autorelease];
    NSLog(@"xmlCheck2 = %@", xmlCheck);
}
这是它被切断的地方,但情况改变了

<td style="font-size: 12.0pt; color: black; font-weight: 400; text-decoration: none; text-underline-style: none; font-family: Arial Narrow; font-style: normal; text-align: general; vertical-align: bottom; white-space: nowrap; border-left: medium none; border-right: 1.0pt solid windowtext; border-top: medium none; border-bottom: 1.0pt solid windowtext; padding-left: 1px; padding-right: 1px; padding-top: 1px; background: #EAF1DD">
    King Pine</td>
    <td style="font-size: 12.0pt; color: black; font-weight: 400; text-decoration: none; text-underline-style: none; font-family: Arial Narrow; text-align: right; font-style: normal; vertical-align: bottom; white-space: nowrap; border-left: medium none; border-right: 1.0pt solid windowtext; border-top: medium none; bor
2012-12-07 19:35:48.652 race tracker[2357:c07] xmlCheck = (null)
2012-12-07 19:43:28.914 race tracker[2357:c07] xmlCheck2 = (null)
2012-12-07 19:43:28.921 race tracker[2357:c07] (
)

松树王

NSMutableData
将增长到任意大小

已经运行了
curlhttp://www.nhara.org/scored_races-2013.htm >txt,我可以告诉你服务器返回的文件长度正好是90810字节。所以这就是为什么你会得到那么多的字节。填充的不是可变数据对象,而是90810正好是正确的长度

你的问题是:

[[NSString alloc] initWithData:xmlData encoding:NSUTF8StringEncoding]
服务器返回的字符串不是有效的UTF-8。要亲自验证这一点,请尝试
NSASCIIStringEncoding
(这是一种所有字节都有效的编码)。您将看到您正确地累积了一个字符串


搜索返回的文件后,具体问题是74963位置的字节-用于排版单引号的0x92。看起来您需要
NSWindowsCP1252StringEncoding
。上传HTML的人似乎使用了Microsoft的代码页1252。

请不要重复几个小时前提出的问题。