Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to preserve Unicode #168

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions JsonConverter.bas
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ Private Type json_Options

' The solidus (/) is not required to be escaped, use this option to escape them as \/ in ConvertToJson
EscapeSolidus As Boolean

' Allow Unicode characters in JSON text. Set to True to use native Unicode or false for escaped values.
AllowUnicodeChars As Boolean
End Type
Public JsonOptions As json_Options

Expand Down Expand Up @@ -575,7 +578,7 @@ Private Function json_ParseString(json_String As String, ByRef json_Index As Lon
json_BufferAppend json_Buffer, vbFormFeed, json_BufferPosition, json_BufferLength
json_Index = json_Index + 1
Case "n"
json_BufferAppend json_Buffer, vbCrLf, json_BufferPosition, json_BufferLength
json_BufferAppend json_Buffer, vbLf, json_BufferPosition, json_BufferLength
json_Index = json_Index + 1
Case "r"
json_BufferAppend json_Buffer, vbCr, json_BufferPosition, json_BufferLength
Expand Down Expand Up @@ -725,9 +728,14 @@ Private Function json_Encode(ByVal json_Text As Variant) As String
Case 9
' tab -> 9 -> \t
json_Char = "\t"
Case 0 To 31, 127 To 65535
Case 0 To 31
' Non-ascii characters -> convert to 4-digit hex
json_Char = "\u" & VBA.Right$("0000" & VBA.Hex$(json_AscCode), 4)
Case 127 To 65535
' Unicode character range
If Not JsonOptions.AllowUnicodeChars Then
json_Char = "\u" & VBA.Right$("0000" & VBA.Hex$(json_AscCode), 4)
End If
End Select

json_BufferAppend json_Buffer, json_Char, json_BufferPosition, json_BufferLength
Expand Down