- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我向使用 JSON 回答我的网络服务器发出发布请求,这是响应的 header :
Cache-Control: private
Content-Length: 826
Content-Type: application/json; charset=utf-8
Date: Wed, 04 Feb 2015 05:53:59 GMT
Server: Microsoft-IIS/8.5
Set-Cookie: ASP.NET_SessionId=0w0mile5232yoqqdlcdomwgf; path=/; HttpOnly
X-Aspnet-Version: 4.0.30319
X-Powered-By: ASP.NET
我解析数据响应(NSURLConnection)并序列化 json :
NSArray *arrayFromServer = [NSJSONSerialization JSONObjectWithData:dataFromServerArray options:NSJSONReadingAllowFragments error:&error];
NSLog(@"string: %@",arrayFromServer);
输出:
string: (
{
altitude = 0;
battery = 100;
"dev_last_contact" = 1423031944;
"device_end_licence" = 1430398189;
"device_type" = hw;
"email_notification" = 0;
"end_user_type" = 0;
"fstk_cnt" = 15;
"fstk_ts" = 0;
heading = 0;
id = 62;
imei = 0123456789APPLE;
inversegeo = "gsm_position ";
label = "Test\Ufffd";
latitude = "45.503731";
"licence_level" = 2;
"licence_status" = valid;
"licence_type" = 1;
longitude = "11.90365";
"md5_image" = CA137B2CB710BC15C87BC6A54D305A2B;
"movement_alert" = 0;
"on_movement" = 0;
"pos_acy" = 1977;
"push_notification" = 0;
refresh = 30;
"req_pos_cnt" = 0;
"req_pos_ts" = 0;
rup = "user_device_list.aspx";
"secure_area" = 0;
"serial_nr" = IOS;
speed = 0;
"text_notification" = 0;
timestamp = 1423031944;
"url_image" = "http://XXXXX.XXXX.XXXX.XXXX/AppImages/1422966751507_62.jpg";
}
)
然后我像这样创建 objectsArray:
devicesArray = [[NSMutableArray alloc] init];
for(NSDictionary *eachDevice in arrayFromServer)
{
//NSLog(@"DEVICE: %@",eachDevice);
Device *device = [[Device alloc] initWithJSONData:eachDevice];
NSString *device_id = [NSString stringWithFormat:@"%ld",(long)[device deviceId]];
[self.all_devices_id addObject:device_id];
[devicesArray addObject:device];
}
我的对象很简单:
.h
@interface Device : NSObject
-(id)initWithJSONData:(NSDictionary*)data;
...
.m
-(id)initWithJSONData:(NSDictionary*)data{
self = [super init];
if(self){
self.deviceId = [[data objectForKey:@"id"] integerValue];
NSLog(@"data label : %@",[data objectForKey:@"label"]);
self.label = [data objectForKey:@"label"];
...
输出是:
data label : Test�
如您所见,“label”在“Test\Ufffd”中转换,然后在 Test� 中转换,但应为“Testè”我对重音字符有疑问,如何才能正确编码该字符串?
谢谢。
最佳答案
您的代码没有问题,因为\Ufffd 是 � 而不是 è 的 unicode。意味着您的服务器返回错误的值。 è 的正确 unicode 是\U00e8 你可以找到它 here , 对于 � 找到 here .我希望这能解决您的问题。
关于ios - 编码的 nsdata utf8 json,在 ios 中带有重音字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28315273/
我正在寻找一种方法来支持不区分大小写 + 重音不区分搜索的良好性能。到目前为止,我们在使用 MSSql 服务器时没有遇到任何问题,在 Oracle 上我们必须使用 OracleText,而现在我们在
这个问题已经有答案了: Trouble with UTF-8 characters; what I see is not what I stored (5 个回答) 已关闭 5 年前。 我刚刚将一个我
我正在寻找一种在 Linux 中使用反引号 (`)/波形符 (~) 键和其他一些键创建键盘快捷键的方法。在理想情况下: 按下波形符没有任何作用 按下波形符的同时按另一个键会触发(可自定义的)快捷方式
我有一个由术语组成的数组,其中一些包含重音字符。我像这样做一个 preg grep $data= array('Napoléon','Café'); $result = preg_grep('~' .
我使用 TextBox 在 DataGridView 中进行过滤 image .这是完美的工作。表格的单元格包含 1250 个拉丁字符。我想搜索忽略单元格中单词的重音。例子。如果是文本框 "knjaz
我在 Vim 中遇到一个奇怪的映射问题。我使用的是 Azerty 键盘。 在我的 .vimrc 中,我有以下命令可以在段落之间快速移动。 nnoremap _ { vnoremap _ { nnore
我尝试读取一个utf8编码的vcf文件,结果是: { "name": "=4A=61=76=69=65=72=20=4C=75=6A=C3=A1=6E", "tel":
我的数据库中有两个表,info 和 comment,它们的结构如下: info (id(int(10)), name(varchar(80)), ...19 other columns.., phon
我使用 QtWebkit 制作了一个应用程序。在同一个 html 页面中,在 Windows 上使用重音符号(西类牙语)时可以正常工作,但在 Linux (Ubuntu) 上则不起作用。 我不明白为什
我有(例如)两个字符串: $a = "joao"; $b = "joão"; if ( strtoupper($a) == strtoupper($b)) { echo $b; } 我希望它是
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: invalid multibyte char (US-ASCII) with Rails and Ruby
我重写 URL 以包含用户生成的旅游博客的标题。 我这样做是为了 URL 的可读性和 SEO 目的。 http://www.example.com/gallery/280-Gorges_du_Tod
我最近安装了新的 Windows 10 build 14393,我想使用新的 linux 子系统。所以我决定学习 ncurses,但我找不到如何从 getch 中获取带有重音符的字符的 UTF-8 代
我是一名优秀的程序员,十分优秀!