Jason Roozee
08/14/2024, 6:13 PMgetHttpRequestData().content
) and one of the values in the JSON contains a UCS2 encoded string (essentially utf-16LE).
Normally, if I am getting a utf-16 string in a form scope, I would simply call setEncoding("form", "utf-8") - and that's it. But I am having a heck of a time trying to convert the value coming from the deserializeJSON of the getHttpRequestData().content
. I've tried UTF-16, UTF-16BE and LE.
The JSON string is: {"msg_id": "f25ac62a-e0a2-4445-9359-06858fd1833c", "message": "桥�?�?"}
I've tried the following:
<cfset content = getHttpRequestData().content>
<cfset data = deserializeJSON(content)>
<cfset msg= CharsetEncode(CharsetDecode(data.message, "UTF-16"), "UTF-8")>
<cffile action="append" file="#ExpandPath(".")#\callback.log" output="#now()# UTF-16:#msg#"/>
<cfset msg= CharsetEncode(CharsetDecode(data.message, "UTF-16BE"), "UTF-8")>
<cffile action="append" file="#ExpandPath(".")#\callback.log" output="#now()# UTF-16BE:#msg#"/>
<cfset msg= CharsetEncode(CharsetDecode(data.message, "UTF-16LE"), "UTF-8")>
<cffile action="append" file="#ExpandPath(".")#\callback.log" output="#now()# UTF-16LE:#msg#"/>
Any ideas? The content (as utf-8) in the "message" is the word "hey"cfvonner
08/14/2024, 6:42 PMgetHttpRequestData()
.content before deserializing the JSON?Jason Roozee
08/14/2024, 6:43 PMJason Roozee
08/14/2024, 6:57 PMJason Roozee
08/14/2024, 8:04 PM<cfset content = getHttpRequestData().content>
<cffile action="write" file="#ExpandPath(".")#\rawdata.bin" output="#content#"/>
<cfset binaryDataRead = fileReadBinary("#ExpandPath(".")#\rawdata.bin") >
<cfset content = CharsetEncode(binaryDataRead, "UTF-8")>
<cfset data = deserializeJSON(content)>
<cfset msgutf16 = data.content>
<cfset msg= CharsetEncode(CharsetDecode(msgutf16, "UTF-16BE"), "UTF-8")>
denny
08/14/2024, 8:43 PMJason Roozee
08/14/2024, 8:52 PMJason Roozee
08/14/2024, 8:53 PMdenny
08/14/2024, 8:54 PM<cfset content = getHttpRequestData().content>
<cfset data = deserializeJSON(content)>
where you are doing implicit conversion to whatever the system is (via deserializeJSON).
Instead of that, you want to always specify a charset when you're switching from binary (getHttpRequestData().content) to text. So theoretically do what you were doing but put this before the the deserialzeJson
call
<cfset json = CharsetEncode(CharsetDecode(getHttpRequestData().content, "UTF-16"), "UTF-8")>
<cfset object = deserializeJSON(data)>
denny
08/14/2024, 8:56 PMJason Roozee
08/14/2024, 8:58 PMdenny
08/14/2024, 9:00 PMisBinary(getHttpRequestData().content)
what does it say?Jason Roozee
08/14/2024, 9:00 PMJason Roozee
08/14/2024, 9:01 PMJason Roozee
08/14/2024, 9:02 PMdenny
08/14/2024, 9:04 PMdenny
08/14/2024, 9:05 PMdeserializeJSON
call regardlessJason Roozee
08/14/2024, 9:07 PMdenny
08/14/2024, 9:09 PMJason Roozee
08/14/2024, 9:09 PMdenny
08/14/2024, 9:21 PMdenny
08/14/2024, 9:25 PMbkbk
08/16/2024, 12:22 PM<cfset content = getHttpRequestData().content>
<cfset content = charsetEncode(content, "UTF-8")>
<cfset data = deserializeJSON(content)>
<cfset msgutf16 = data.content>
<cfset msg = charsetEncode(charsetDecode(msgutf16, "UTF-16BE"), "UTF-8")>
denny
08/16/2024, 4:20 PMcontent.getBytes()
(since it's text vs. binary) for that charsetEncode
but that should be the same, neh?