如果度符号在json对象中,则JSONObjectWithData返回null

时间:2012-07-05 17:54:01

标签: iphone xcode json nsjsonserialization

如果json字符串包含度数符号°(U + 00B0),则JSONObjectWithData返回null而没有错误。如果我将它提供给桌面浏览器,json字符串显示正常。

我的代码(一个类别)有几个NSLog来查看发生的事情就像这样......

+(NSDictionary*)dictionaryWithContentsOfJSONURLString:(NSString *)urlAddress{
     __autoreleasing NSError* error = nil;
    NSData* data = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlAddress] options:NSDataReadingUncached error:&error];
    if (error != nil) {
        NSLog(@"%@",[error localizedDescription]);        
    }   else {
        NSLog(@"No Error: %@", data);  //looks good here. console displays the raw data 
    }

    id result = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];

    if (error != nil) {
        NSLog(@"%@",[error localizedDescription]);
        return nil;

    }   else {
        NSLog(@"No Error: %@", [result objectForKey:@"exams"]); //console displays the value ("No Error: value for key...") unless a degree symbol is present in which case it displays No Error: (null)

    }

    return result;

 }

所以我没有收到任何错误,但如果收到的json字符串包含一个度数符号,则JSONOBjectWithData返回null。

我使用带有URL内容的NSString来查看xCode如何看到字符串,而不是我得到的度数符号,我认为是一个省略号∞符号。在浏览器中查看时,相同的字符串是度数符号。

这是一个错误吗?我一定错过了什么。

谢谢,

约翰

0 个答案:

没有答案
相关问题