gpt4 book ai didi

iOS - NSJSON 序列化 : Unable to convert data to string around character

转载 作者:可可西里 更新时间:2023-11-01 05:00:44 25 4
gpt4 key购买 nike

解析 JSON 时出现此错误:

NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];

Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Unable to convert data to string around character 73053.) UserInfo=0x1d5d8250 {NSDebugDescription=Unable to convert data to string around character 73053.}

有什么解决办法吗?

已添加正如它在错误报告中所说,解析器无法通过位置 73053 处的字符,它在我的 JSON 响应中是“ø”。据我所知,Ø、Å、Æ 等字符对于 json 解析器应该不是问题吗?

最佳答案

是的,我在编码问题上遇到了同样的问题,并得到了上述错误。我从服务器获取 NSData 作为 encoding:NSISOLatin1StringEncoding。所以我必须在使用 NSJSONSerialization 解析它之前将它转换为 UTF8。

NSError *e = nil;
NSString *iso = [[NSString alloc] initWithData:d1 encoding:NSISOLatin1StringEncoding];
NSData *dutf8 = [iso dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:dutf8 options:NSJSONReadingMutableContainers error:&e];

关于iOS - NSJSON 序列化 : Unable to convert data to string around character,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14321033/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com