0

我有一个从 Web 获取数据的应用程序,它使用 XMLParser 并使用此代码块对其进行序列化。几天前它曾经工作正常,但它停止工作:

-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{

    NSLog(@"Element ended %@",elementName);
    if ([self.currentElement isEqualToString:@"string"]) {
        //THIS LOGS THE CHARACTERS RECEIVED FROM THE SERVER
        NSLog(@"The characters are %@", self.currentValue);
        NSData *theData = [self.currentValue dataUsingEncoding:NSUTF8StringEncoding];
        NSError *error;
        NSLog(@"The Data parameter you pass in:%@", theData);
        self.valuesDictionary = [[NSDictionary alloc] init];
        self.valuesDictionary = [NSJSONSerialization JSONObjectWithData:theData options:0 error:&error];

        if (error) {
            NSLog(@"Error = %@", error);
        }

        if ([self.valuesDictionary isKindOfClass:[NSDictionary class]]) {
            //THIS LOGS THE RECEIVED RESPONSE IN IOS OBJECT FORMAT
            NSLog(@"dataDictionary %@", self.valuesDictionary);
            [self writeJSONResponse:self.valuesDictionary toDiskForClassWithName:@"Location"];
        }
    }

    self.currentElement = nil;
    self.currentValue = nil;
}

self.currentValue 打印出包含 2 个条目的正确字典: -recordcount -data

theData 退出到看起来不错的状态

但 self.valuesDictionary 永远不会被填充。我在每一行都有断点,当我到达 if-test 时,self.valuesDictionary 在变量控制台视图中没有任何值,如果我将它记录为 nil。我记录了错误并得到:

NSDebugDescription=字符 43579 周围未转义的控制字符。

很明显,网络服务发生了一些变化。我该如何解释?

4

0 回答 0