emoji表情转码

iOS

编码

1
2
3
4
5
6
7
8
[@"带表情的字符串" stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLPathAllowedCharacterSet]];

URLFragmentAllowedCharacterSet "#%<>[\]^`{|}
URLHostAllowedCharacterSet "#%/<>?@\^`{|}
URLPasswordAllowedCharacterSet "#%/:<>?@[\]^`{|}
URLPathAllowedCharacterSet "#%;<>?[\]^`{|}
URLQueryAllowedCharacterSet "#%<>[\]^`{|}
URLUserAllowedCharacterSet "#%/:<>?@[\]^`

解码

1
[@"编码过带表情的字符串" stringByRemovingPercentEncoding];
Android

编码

1
URLEncoder.encode( "带表情的字符串", "UTF-8" );

解码

1
URLDecoder.decode( "编码过带表情的字符串", "UTF-8" )