IOS - UTF-8轉碼問題

2016.07.06 21:45*?字數 61?閱讀 921評論 0

IOS中提供的轉碼。

[utf8str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

?

轉碼后發現,與java的不一樣。

原來IOS中轉碼的標準不一致,導致出現錯誤。

不過,可以使用下面的方法來替換,就OK了。

utf8str = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? (CFStringRef)utf8str,

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? NULL,

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? CFSTR(":/?#[]@!$ &'()*+,;=\"<>%{}|\\^~`"),

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? kCFStringEncodingUTF8));

?

iOS網絡請求返回的漢字在日志里會顯示成\U63d0\U4ea4\U6210\U529f,用下面的腳本就可以把Unicode顯示成漢字

#!/bin/sh

cmd="/usr/bin/env python -c 'print(\"\"\"$1\"\"\".lower().decode(\"unicode-escape\").encode(\"utf-8\"))'"

echo $cmd | sh

?

比如:把這個腳本命名為co,并使用chmod +x co添加可執行屬性

使用co '\U63d0\U4ea4\U6210\U529f'就可以顯示漢字了。

?

轉載于:https://www.cnblogs.com/sundaysgarden/p/10412524.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/278296.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/278296.shtml
英文地址,請注明出處:http://en.pswp.cn/news/278296.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

手把手教你如何實現繼承

本文將從最簡單的例子開始&#xff0c;從零講解在 JavaScript 中如何實現繼承。 小例子 現在有個需求&#xff0c;需要實現 Cat 繼承 Animal &#xff0c;構造函數如下&#xff1a; function Animal(name){this.name name }function Cat(name){this.name name } 復制代碼注&a…

最詳細的排序解析,理解七大排序

最詳細的排序解析&#xff0c;理解七大排序 mp.weixin.qq.com點擊上方“方志朋”&#xff0c;選擇“置頂或者星標” 你的關注意義重大&#xff01; 注&#xff1a; lgN在這里為1og2N簡寫 為了方便描述,本文默認用int類型比較&#xff0c;從小到大排序 本文排序算法以java語言…

xp刪除管理員賬戶_在Windows XP中從登錄屏幕刪除用戶帳戶

xp刪除管理員賬戶So you login to your computer every single day, but there’s more than one account to choose from… either because you got the computer from somebody else, or some software package added a user account that you really don’t want to see. So…

Java網絡爬蟲實操(8)

上一篇&#xff1a;Java網絡爬蟲實操&#xff08;7&#xff09; 大家好&#xff0c;本篇文章介紹一下NetDiscovery爬蟲框架里的downloader對象 1) 前言 面向對象設計仍然是目前編程的核心思想&#xff0c;從下面截圖可以了解爬蟲框架的主要對象&#xff1a; 程序在本地組織好一…

Pycharm下將py文件打包成exe文件

1. 在PyCharm下安裝PyInstaller 1. 首先&#xff0c;打開自己要發布的工程 2. 點擊底部的【Terminal】打開終端&#xff0c;中輸入命令pip install pyinstaller后回車&#xff0c;如圖所示進行安裝 3. 輸入命令 pyinstaller&#xff0c;回車顯示安裝成功 4. 輸入命令 pyinstall…

什么是自然語言處理,它如何工作?

NicoElNino/Shutterstock.comNicoElNino / Shutterstock.comNatural language processing enables computers to process what we’re saying into commands that it can execute. Find out how the basics of how it works, and how it’s being used to improve our lives. 自…

GIT速查手冊

為什么80%的碼農都做不了架構師&#xff1f;>>> 一、GIT 1.1 簡單配置 git是版本控制系統&#xff0c;與svn不同的是git是分布式&#xff0c;svn是集中式 配置文件位置 # 配置文件 .git/config 當前倉庫的配置文件 ~/.gitconfig 全局配置文件# 查看所有配置項 git …

4-3邏輯非運算符及案例 4-4

創建類 LoginDemo3 這里取反 !(n%30) package com.imooc.operator; import java.util.Scanner;public class LoginDemo3 {public static void main(String[] args) {// TODO Auto-generated method stubSystem.out.println("請輸入一個整數");Scanner scnew Scanner(…

assistant字體_如何使用Google Assistant設置和致電家庭聯系人

assistant字體Google谷歌Google Home and Nest smart speakers and displays allow you to make calls without using your phone. By setting up “Household Contacts,” anyone in your home can easily call friends and family members with Google Assistant-enabled dev…

php隊列使用

由于項目中在修改產品的同時要同步關聯水單,刪單&#xff0c;客保 等等數據。所以不可能等待所有都執行完畢以后再給客戶端反饋。所以自己用寫了個隊列。在這里曬出來代碼&#xff0c;以供大家參考。(項目中用到的是tp,所以在這里用tp作為演示) 思路 1&#xff0c;需要用到隊列…

Accoridion折疊面板

詳細操作見代碼&#xff1a; <!doctype html> <html><head><meta charset"UTF-8"><title></title><meta name"viewport" content"widthdevice-width,initial-scale1,minimum-scale1,maximum-scale1,user-scal…

skype快捷鍵_每個Skype鍵盤快捷鍵及其用法

skype快捷鍵Roberto Ricca/Shutterstock羅伯托里卡/ ShutterstockGet familiar with Skype’s unique keyboard shortcuts that will allow you to quickly change your settings, alter your interface, and control your communications. Use these hotkeys and become a Sky…

習慣需要堅持

近期會把本地的資料上傳分享出來&#xff0c;好久沒更新自己的內容了&#xff0c;以后會不斷的更新哦。轉載于:https://blog.51cto.com/haohao1010/2087494

YouTube鍵盤快捷鍵:速查表

Google’s video website wouldn’t be complete without all sorts of useful buttons and hidden commands that aren’t immediately obvious. Use this hotkey cheat sheet to quickly navigate YouTube and gain better control over your video browsing experience. 如果…

第五章 課本題目

例 5.1 使用單分支條件結構輸出兩個數的最大值。 #include<stdio.h> int main() { int a,b,max; scanf("%d,%d",&a,&b); if(a>b) maxa; if(a<b) maxb; printf("max%d\n",max); return 0; } 例 5.2 用雙分支條件語句求最大值。 #includ…

MySQL服務讀取參數文件my.cnf的規律研究探索

在MySQL中&#xff0c;它是按什么順序或規律去讀取my.cnf配置文件的呢&#xff1f;其實只要你花一點功夫&#xff0c;實驗測試一下就能弄清楚&#xff0c;下面的實驗環境為5.7.21 MySQL Community Server。其它版本如有不同&#xff0c;請以實際情況為準。 其實&#xff0c;MyS…

將組策略編輯器添加到控制面板

If you find yourself using the Group Policy Editor all the time, you might have wondered why it doesn’t show up in the Control Panel along with all the other tools. After many hours of registry hacking, I’ve come up with a registry tweak to let you do ju…

cookies和session區別

cookies和session區別 1、Cookie和Session都是會話技術&#xff0c;Cookie是運行在客戶端&#xff0c;Session是運行在服務器端。 2、Cookie有大小限制以及瀏覽器在存cookie的個數也有限制&#xff0c;Session是沒有大小限制和服務器的內存大小有關。3、Cookie有安全隱患&#…

Exchange Server 2016管理系列課件50.DAG管理之激活數據庫副本

激活郵箱數據庫副本是將特定被動副本指定為郵箱數據庫的新主動副本的過程。我們將此過程稱為數據庫切換。數據庫切換過程是指卸除當前的活動數據庫&#xff0c;然后在指定的服務器上將相應的數據庫副本作為新的活動郵箱數據庫副本進行裝載。成為活動郵箱數據庫的數據庫副本必須…

常見設計模式 (python代碼實現)

1.創建型模式 單例模式 單例模式&#xff08;Singleton Pattern&#xff09;是一種常用的軟件設計模式&#xff0c;該模式的主要目的是確保某一個類只有一個實例存在。當你希望在整個系統中&#xff0c;某個類只能出現一個實例時&#xff0c;單例對象就能派上用場。 比如&#…