在json中为javascript:hex转义字符串 [英] Escape string for javascript: hex in json
本文介绍了在json中为javascript:hex转义字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此字符串
{\x22Address\x22:\x22some带引号的地址\\x22 \x22}
在浏览器中被JSON.parse正确解析。为什么? json字符串中十六进制数字的含义是什么?我找不到解释。
解决方案
在Javascript中,反斜线是一个转义字符。有几个转义序列,您可以在此处查找列表。
最重要的是:
\x
后面跟着两个十六进制字符,用ASCII代码表示一个字符 \u
后跟四个十六进制字符, unicode number \ t
, \r
, \\\
你当然知道。它们分别是制表符,回车符和换行符。This string
{\x22Address\x22:\x22some address with quotes \\x22 \x22}
is parsed by JSON.parse correctly in browser. Why? What do hex numbers mean in json string? I can't find explanation.
解决方案
In Javascript a backslash is an escape character. There are several escape sequences, you can find a list here.
The most important:
\x
followed by two hexadecimal characters represent a character by it's ascii code\u
followed by four hexadecimal characters represent a character by it's unicode number\t
,\r
,\n
you certainly know already. They are tab, carriage return and new line respectively.
这篇关于在json中为javascript:hex转义字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文