This is indeed not binary, it is unicode encoding. You can use the p command in lldb or the echo command in the shell to print these encodings, both of which can be printed out in a readable format. of Chinese. p 命令或在 shell 中使用 echo 命令打印这些编码,均可打印出可读的中文。
补充:最近在使用 p 命令时,发现 p "U4e3dU5c71" 这种形式打印会报错 error: incomplete universal character name ,发现 u 的大小写是不一样,应该的形式是 p "u4e3du5c71" (四位)或者 p "U00004e3dU00005c71"(八位)。虽然没找到明确文字说明,但可以推论出,小写的是 BMK
Starting from iOS 5 (no verification, but the early printed arrays and dictionaries are consistent with the current printed object display, <name: memory address>), printed arrays and dictionaries display specific data structures (description method), which is more convenient for debugging, but no processing is done when printing the string (such as character escaping here). Because it is only for debugging, and when printing a specific string, when calling the desciption method of the string, it will be escaped into readable Chinese, that is, it will be automatically escaped when it is processed specifically, and it is not necessary. You should change it yourself.
🎜🎜If you have to display Chinese on the console, you can do this, NSLog(@"%@",[NSString stringWithCString:[[dictionary description] cStringUsingEncoding:NSUTF8StringEncoding] encoding:NSNonLossyASCIIStringEncoding]);; you can also repeat Write the description method. But I personally feel that this is not necessary. 🎜🎜
🎜🎜Supplement: Recently when using the p command, I found that p "U4e3dU5c71" will report an error error: incomplete universal character name when printing in this form. I found that the capitalization of u is different. The correct form is p "u4e3du5c71" (four digits) or p "U00004e3dU00005c71" (eight digits). ). Although no clear text explanation was found, it can be inferred that the lower case is BMK🎜[NSString and Unicode]🎜, which defaults to plane 0 and the first four digits are 0 by default. 🎜🎜
🎜
An iOS development novice answered angrily. First of all, let me correct you, "u8bc4u8bbau6807u9898"is Unicode encoding, not "binary" as the questioner mentioned. So just decode Unicode and convert it into Chinese~ There are probably two ways to solve it This question~
Use an online conversion tool. There are a lot of searches on Baidu so I won’t give specific examples;
Write a tool class for conversion and paste the code below;
This is indeed not binary, it is unicode encoding. You can use the
p
command in lldb or theecho
command in the shell to print these encodings, both of which can be printed out in a readable format. of Chinese.p
命令或在 shell 中使用echo
命令打印这些编码,均可打印出可读的中文。从 iOS 5 开始(没有验证,但早期打印数组和字典均和现在打印对象的显示一致,<名称:内存地址>),打印数组和字典显示出具体的数据结构(
description
方法),更方便了调试,但其中打印字符串时并未做任何处理(如此处的字符转义)。由于只是便于调试,而且打印具体字符串时,调用字符串的desciption
方法时,会转义为可读中文,也就是到具体处理的时候会自动转义,不用也不应该自己去转。非得在控制台显示中文的话可以这样,
NSLog(@"%@",[NSString stringWithCString:[[dictionary description] cStringUsingEncoding:NSUTF8StringEncoding] encoding:NSNonLossyASCIIStringEncoding]);
;也可以重写description
方法。但个人感觉其实没有这个必要。补充:最近在使用
Starting from iOS 5 (no verification, but the early printed arrays and dictionaries are consistent with the current printed object display, <name: memory address>), printed arrays and dictionaries display specific data structures (p
命令时,发现p "U4e3dU5c71"
这种形式打印会报错error: incomplete universal character name
,发现u
的大小写是不一样,应该的形式是p "u4e3du5c71"
(四位)或者p "U00004e3dU00005c71"
(八位)。虽然没找到明确文字说明,但可以推论出,小写的是BMK
description
method), which is more convenient for debugging, but no processing is done when printing the string (such as character escaping here). Because it is only for debugging, and when printing a specific string, when calling thedesciption
method of the string, it will be escaped into readable Chinese, that is, it will be automatically escaped when it is processed specifically, and it is not necessary. You should change it yourself.NSLog(@"%@",[NSString stringWithCString:[[dictionary description] cStringUsingEncoding:NSUTF8StringEncoding] encoding:NSNonLossyASCIIStringEncoding]);
; you can also repeat Write thedescription
method. But I personally feel that this is not necessary. 🎜🎜 🎜🎜Supplement: Recently when using thep
command, I found thatp "U4e3dU5c71"
will report an errorerror: incomplete universal character name
when printing in this form. I found that the capitalization ofu
is different. The correct form isp "u4e3du5c71"
(four digits) orp "U00004e3dU00005c71"
(eight digits). ). Although no clear text explanation was found, it can be inferred that the lower case isBMK
🎜[NSString and Unicode]🎜, which defaults to plane 0 and the first four digits are 0 by default. 🎜🎜 🎜Convert json to dictionary and get data based on key value
An iOS development novice answered angrily.
First of all, let me correct you,
"u8bc4u8bbau6807u9898"
is Unicode encoding, not "binary" as the questioner mentioned.So just decode Unicode and convert it into Chinese~ There are probably two ways to solve it This question~
Use an online conversion tool. There are a lot of searches on Baidu so I won’t give specific examples;
Write a tool class for conversion and paste the code below;
Post directly in lldb