SBJson - UTF8字符

时间:2013-11-28 11:02:18

标签: utf-8 sbjson

我有一些包含UTF8字符的数据。如果我这样做,我可以在控制台中正确地看到字符:

NSString *responseData = [[NSString alloc]
                                  initWithData:urlData
                                  encoding:NSUTF8StringEncoding];
NSLog(@"Response = %@", responseData);


输出
{"success":1,"row":1,"no":"001","title":"Arendi iOS","subject":"Konu 1","describtion":"Aciklama 1 ıİöÖçÇüÜğĞ","attachment":"Eklenti 1","status":1}

在这一步之后,我这样做:

SBJsonParser *jsonParser = [SBJsonParser new];
NSDictionary *jsonData = (NSDictionary*)[jsonParser objectWithString:responseData error:nil];
NSLog(@"jsonData = %@",jsonData);

输出:

jsonData = {
    attachment = "Eklenti 2";
    describtion = "Aciklama 2 \U0131\U0130\U00f6\U00d6\U00e7\U00c7\U00fc\U00dc\U011f\U011e";
    no = 002;
    row = 2;
    status = 1;
    subject = "Konu 2";
    success = 1;
    title = "Arendi Android";
}

之后我这样做:

NSString *description = (NSString*)[jsonData objectForKey:@"description"];

但它给了我null。如何正确打印这些字符?

1 个答案:

答案 0 :(得分:1)

不确定这是不是一个简单的拼写错误,但我不禁注意到你在这里有一个名为“description”的字段。

  

jsonData = {      attachment =“Eklenti 2”;      descrition =“Aciklama 2 \ U0131 \ U0130 \ U00f6 \ U00d6 \ U00e7 \ U00c7 \ U00fc \ U00dc \ U011f \ U011e”;      no = 002;      row = 2;      status = 1;      subject =“Konu 2”;      成功= 1;      title =“Arendi Android”;   }

但是在最终输出中,您试图获取名为“description”的属性的值。如果key被定义为“describetion”,则无法通过“description”找到它,并且解析器将按预期返回“null”。

希望它有所帮助。

相关问题