简体   繁体   English

在Json Parsing中解析双引号和单引号

[英]Parse double quotes and single quotes in Json Parsing

I am parsing a JSON url. 我正在解析JSON网址。 I am getting \â\€\œ instead of single quotes and \â\€\ instead of double quotes. 我得到的是\â\€\œ而不是单引号,并且是\â\€\而不是双引号。 On my end i am doing NSUTF8StringEncoding but still not getting single and double quotes. 在我的一端,我正在做NSUTF8StringEncoding但仍然没有得到单引号和双引号。

Here is the response in the web browser: 这是Web浏览器中的响应:

{"status":"1","data":[{"id":"1345","title_en":"","content_en":"Mom said, \â\€\œI love this one.\â\€\\\n\\nJake said, \â\€\œI don\â\€\™t get it.\â\€\\\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":"The Art Museum","author_url":"maureen-d-1","book_url":"the-art-museum","video_filename":"","sound_filename":"atmuseum2.m4a"}]} {“状态”:“ 1”,“数据”:[{“ id”:“ 1345”,“ title_en”:“”,“ content_en”:“妈妈说,\\ u00e2 \\ u20ac \\ u0153我喜欢这个。\\ u00e2 \\ u20ac \\ u009d \\ n \\ nJake说,\\ u00e2 \\ u20ac \\ u0153我不要\\ u00e2 \\ u20ac \\ u2122t得到它。\\ u00e2 \\ u20ac \\ u009d \\ n“,” image“:” 1396“,” pos“:” 2 “,” video_type“:” 0“,” video“:” 0“,” video_alt“:”“,” sound_type“:” 1“,” sound“:” 1123“,” sound_alt“:”“,”作者“:”“,” type“:” 0“,” book_id“:” 148“,” user_id“:” 24“,” title“:”艺术博物馆“,” author_url“:” maureen-d-1“ ,“ book_url”:“艺术博物馆”,“ video_filename”:“”,“ sound_filename”:“ atmuseum2.m4a”}]}

Is it possible to parse above response using NSUTF8StringEncoding or something else. 是否可以使用NSUTF8StringEncoding或其他方法解析以上响应。 Or i need to get it done from php side. 或者我需要从PHP方面完成它。

Do you use NSJSONSerialization? 您是否使用NSJSONSerialization? In my app i do this: 在我的应用程序中,我这样做:

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

In "data" variable i have response from server. 在“数据”变量中,我收到了服务器的响应。 I receiving UTF-encoded text from server too (like \â\€) but finally i get normal string. 我也从服务器接收UTF编码的文本(如\\ u00e2 \\ u20ac),但最终我得到了正常的字符串。 "jsonObjects" will contain data in native types: “ jsonObjects”将包含本机类型的数据:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM