Skip to content

Commit 22a463a

Browse files
blindlftimhall
authored andcommitted
Encoding Chinese character
AscW will return negative value in the case of some Chinese character.
1 parent e4ff708 commit 22a463a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

JsonConverter.bas

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,13 @@ Private Function json_Encode(ByVal json_Text As Variant) As String
502502
For json_Index = 1 To VBA.Len(json_Text)
503503
json_Char = VBA.Mid$(json_Text, json_Index, 1)
504504
json_AscCode = VBA.AscW(json_Char)
505+
506+
' When AscW returns a negative number, it returns the twos complement form of that number.
507+
' To convert the twos complement notation into normal binary notation, add 0xFFF to the return result.
508+
' https://support.microsoft.com/en-us/kb/272138
509+
If json_AscCode < 0 Then
510+
json_AscCode = json_AscCode + 65536
511+
End If
505512

506513
Select Case json_AscCode
507514
' " -> 34 -> \"

0 commit comments

Comments
 (0)