Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/9.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
Iphone 未转换控件字符的间歇性JSON解析器故障_Iphone_Objective C_Json_Ios - Fatal编程技术网

Iphone 未转换控件字符的间歇性JSON解析器故障

Iphone 未转换控件字符的间歇性JSON解析器故障,iphone,objective-c,json,ios,Iphone,Objective C,Json,Ios,iPhone应用程序中的功能,用于搜索twitter上的某些文本。代码非常简单,我将url字符串传递给TwitterAPI,然后解析结果。尽管JSON解析器有一半的时间会因未转义控制字符“0x0”的错误而失败。下面是代码和完整的错误消息 - (void)grabData:(NSString *)searchTerm { NSString *urlString = [NSString stringWithFormat:@"http://search.twitter.com/sea

iPhone应用程序中的功能,用于搜索twitter上的某些文本。代码非常简单,我将url字符串传递给TwitterAPI,然后解析结果。尽管JSON解析器有一半的时间会因未转义控制字符“0x0”的错误而失败。下面是代码和完整的错误消息

    - (void)grabData:(NSString *)searchTerm {
     NSString *urlString = [NSString stringWithFormat:@"http://search.twitter.com/search.json?q=%@&rpp=25",searchTerm];

     NSURL *url = [NSURL URLWithString:urlString];

     NSLog(@"Created url:%@",url);

     //Setup and start async download
     NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
     NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
     [connection release];
     [request release];
    }

    - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {

     // Store incoming data into a string
     NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

     //NSLog(@"Did receive some data %@",jsonString);

     //Create a dictionary from the JSON string
     NSDictionary *results = [jsonString JSONValue];

     // Build an Array from the dictionary for easy access to each entry
     NSDictionary *tweets = [results objectForKey:@"results"];

            // Loop through each entry in the dictionary
    for(NSDictionary *tweet in tweets) {
     // Get the user string for the tweet
     NSString *tUser = [tweet objectForKey:@"from_user"];
           NSLog(@"Tweet from %@",tUser);
          }

    }
来自控制台的错误消息,50%的时间,其他50%的时间按预期工作

2010-12-20 21:22:02.022 TwitterSearch[47362:207] Created url:http://search.twitter.com/search.json?q=red&rpp=25
2010-12-20 21:22:02.361 TwitterSearch[47362:207] -JSONValue failed. Error trace is: (
    "Error Domain=org.brautaset.JSON.ErrorDomain Code=5 \"Unescaped control character '0x0'\" UserInfo=0x4d6a130 {NSLocalizedDescription=Unescaped control character '0x0'}",
    "Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \"Object value expected for key: profile_image_url\" UserInfo=0x4d6a200 {NSUnderlyingError=0x4d6a170 \"Unescaped control character '0x0'\", NSLocalizedDescription=Object value expected for key: profile_image_url}",
    "Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \"Expected value while parsing array\" UserInfo=0x4d6a240 {NSUnderlyingError=0x4d6a1e0 \"Object value expected for key: profile_image_url\", NSLocalizedDescription=Expected value while parsing array}",
    "Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \"Object value expected for key: results\" UserInfo=0x4d6a310 {NSUnderlyingError=0x4d6a2d0 \"Expected value while parsing array\", NSLocalizedDescription=Object value expected for key: results}"
)

didReceiveData
方法可以在数据传递时多次调用。因此,在该方法中,您只需将每个传入块附加到NSMutableData类变量(而不是处理它)

应使用
connectiondFinishLoading
方法处理完整数据


发生此错误可能是因为它试图解析部分数据块。

而JSON失败时会是什么样子?