gpt4 book ai didi

ios - 解析具有不同本地的 JSON 字符串(无英文)

转载 作者:行者123 更新时间:2023-11-29 11:14:47 25 4
gpt4 key购买 nike

我得到了以下 JSON 字符串,我面临解析问题,因为它包含非英语本地:

{"error":0,"token":"59188a107d705f8c51585d719769e0642ce98b79d86fdace30dbc58efba301cc","status":"200","messages":[{"update_time":"2012-03-31 22:50:13","seq":"497","lng":58.4235,"msg":"hhhh : Ÿ?Ÿ? ÿ™ÿ™ÿߟ?ÿ™ ","lat":23.5866}],"error_msg":""}

我正在尝试使用以下代码:

NSError* error;
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData //1
options:kNilOptions
error:&error];

如果它只有英文,它工作正常,我怎么能在 JSON 中解析非英文本地。

最佳答案

来自docs :

The data must be in one of the 5 supported encodings listed in the JSON specification: UTF-8, UTF-16LE, UTF-16BE, UTF-32LE, UTF-32BE. The data may or may not have a BOM. The most efficient encoding to use for parsing is UTF-8, so if you have a choice in encoding the data passed to this method, use UTF-8.

由于您的字符串在 Safari 中显示不正确,我怀疑它没有以这些格式之一进行编码。您需要将数据重新编码为合法的 JSON 编码。

关于ios - 解析具有不同本地的 JSON 字符串(无英文),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9958725/

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