|
本帖最后由 smsn 于 2023-1-10 14:29 编辑
好的,明白。
以防有人可能有人会找到这贴,说下以下内容。
json 标准在这里有规定 http://www.json.org.cn/ ,字符怎么转都有标准。
http://www.rfc-editor.org/rfc/pdfrfc/rfc4627.txt.pdf
一些控制符和下图这几个有特殊要求。
例如 回车换行用的是 \r \n 不是直接unicode,还要加转义符号。
字符转化程序:
- Public Function toUnicode(str As String) As String 'JSON format
- Dim x As Long
- Dim uStr As String
- Dim uChrCode As Integer
- For x = 1 To Len(str)
- uChrCode = AscW(Mid(str, x, 1)) 'or Asc
- Select Case uChrCode
- Case 8: ' backspace
- uStr = uStr & "\b"
- Case 9: ' tab
- uStr = uStr & "\t"
- Case 10: ' line feed
- uStr = uStr & "\n"
- Case 12: ' formfeed
- uStr = uStr & "\f"
- Case 13: ' carriage return
- uStr = uStr & "\r"
- Case 34: ' quote
- uStr = uStr & """"
- Case 39: ' apostrophe
- uStr = uStr & "\'"
- Case 92: ' backslash
- uStr = uStr & "\"
- Case 123, 125: ' "{" and "}"
- uStr = uStr & ("\u" & Right("0000" & Hex(uChrCode), 4))
- Case Is < 32, Is > 127: ' non-ascii characters
- uStr = uStr & ("\u" & Right("0000" & Hex(uChrCode), 4))
- Case Else
- uStr = uStr & ChrW$(uChrCode)
- End Select
- Next
- toUnicode = uStr
- End Function
复制代码
|
|