JSON数据在iOS中无法正确序列化

时间:2013-08-30 00:35:12

标签: ios json nsjsonserialization

我有一个从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

数据记录到看起来很好的

但是从不填充self.valuesDictionary。我在每一行都有断点,当我进入if-test时,self.valuesDictionary在变量控制台视图中没有值,如果我将其记录为零。我记录了错误并得到了:

  

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

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

0 个答案:

没有答案