【问题标题】:Parse double quotes and single quotes in Json Parsing在 Json Parsing 中解析双引号和单引号
【发布时间】:2013-01-23 17:11:05
【问题描述】:

我正在解析一个 JSON 网址。我得到\u00e2\u20ac\u0153 而不是单引号和\u00e2\u20ac\u009d 而不是双引号。就我而言,我正在做NSUTF8StringEncoding,但仍然没有得到单引号和双引号。

这是网络浏览器中的响应:

{"status":"1","data":[{"id":"1345","title_en":"","content_en":"妈妈 说,\u00e2\u20ac\u0153我喜欢这个。\u00e2\u20ac\u009d\n\nJake 说,\u00e2\u20ac\u0153I don\u00e2\u20ac\u2122t get 它。\u00e2\u20ac\u009d\n","image":"1396","pos":"2","video_type":"0","video":"0","video_alt":"" ,"sound_type":"1","sound":"1123","sound_alt":"","author":"","type":"0","book_id":"148","user_id" :"24","title":"该 艺术 博物馆","author_url":"maureen-d-1","book_url":"the-art-museum","video_filename":"","sound_filename":"atmuseum2.m4a"}]}

是否可以使用NSUTF8StringEncoding 或其他方式解析上述响应。或者我需要从 php 端完成它。

【问题讨论】:

    标签: ios objective-c json ipad encoding


    【解决方案1】:

    你使用 NSJSONSerialization 吗?在我的应用程序中,我这样做:

    NSError* localError;
    id jsonObjects = [NSJSONSerialization JSONObjectWithData:data
                                                     options:NSJSONReadingMutableContainers
                                                       error:&localError];
    

    在“数据”变量中,我有来自服务器的响应。我也从服务器接收 UTF 编码的文本(如 \u00e2\u20ac),但最后我得到了正常的字符串。 “jsonObjects”将包含原生类型的数据:

        if ([jsonObjects isKindOfClass:[NSDictionary class]])
        {
            NSNumber* age = [jsonObjects objectForKey:@"age"];
        //...etc
        }
    

    【讨论】:

    • 我检查了我的应用程序。来自服务器的回答中的引号没有 UTF 编码。单引号看起来像 \"。双引号:\"\"。我试图在像这样json.parser.online.fr 这样的 json 在线解码器上解码你的 JSON 而这个编码 \u00e2\u20ac\u0153 似乎被破坏了。所以我认为问题在服务器端编码,不在你的 Objective-C 代码中。这是我的看法。
    猜你喜欢
    • 2021-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-05
    • 2011-05-08
    • 2012-04-24
    • 2014-04-28
    相关资源
    最近更新 更多