JSON Encode/Decode

I'm receiving a JSON message through Web Server.

But some weird caracteres appears. And I dont know how to convert to UTF-8.


Function GetApi0010(url,txt)
Dim http,ret,lenght,aux, sts
Set http = CreateObject("MSXML2.ServerXMLHTTP.6.0")
http.setTimeouts 1000, 1000, 1000, 1000
http.open "POST", url, True
http.setRequestHeader "Content-type", "application/json; charset=utf-8"
http.send(txt)
http.waitForResponse 200 Or 4
aux = http.responseText
End Function


The response is:

aux = OB 302764 informada estom status Encerrada onde nossivel iniciar/continuar a fase! Somente OB s com status Emitida ou Programada podem ser utilizadas.

In the server the message is:

aux = OB 302764 informada está com status Encerrada onde não é possivel iniciar/continuar a fase! Somente OB s com status Emitida ou Programada podem ser utilizadas.


Someone have any idea how to convert? Or Where the problem is?

:unsure:
Parents
  • It looks like the original text is encoded as a single byte per character(not UTF-8) and somewhere along the line, something is trying to convert it from UTF-8. Everywhere there is a character with a value greater than 127, something assumes it is in UTF-8 and consumes 3 bytes (in your example, it could be 2 or 4 bytes for other characters) for that character. You may need to use wireshark to see what the binary data looks like.

    There are ways to convert between different encodings using VBScript. ADODB.Stream pops up a lot in internet searches.
Reply
  • It looks like the original text is encoded as a single byte per character(not UTF-8) and somewhere along the line, something is trying to convert it from UTF-8. Everywhere there is a character with a value greater than 127, something assumes it is in UTF-8 and consumes 3 bytes (in your example, it could be 2 or 4 bytes for other characters) for that character. You may need to use wireshark to see what the binary data looks like.

    There are ways to convert between different encodings using VBScript. ADODB.Stream pops up a lot in internet searches.
Children
No Data