I'm receiving a JSON response from an API with the following format:
{"type": "Buffer","data": [23, 23, 23, 23, 23]}In NodeJS, decoding this is simple. Here's the code:
const response = await Api.get("endpoint", { params: { param1: value, param2: value, }, responseType: "arraybuffer", headers: { Authorization: bearer, },});The response will have the decoded content I need.
In Delphi, I am using the native RESTClient to extract data from the API. The raw binary data didn't fit my expectations. Here's an example of the code I tried to extract the ByteArray from the JSON:
for i := 0 to DataArray.Count - 1 dobegin JSONValue := DataArray.Items[i]; if JSONValue is TJSONNumber then begin ByteValue := StrToIntDef(TJSONNumber(JSONValue).ToString, 0) and $FF; ByteArray[i] := ByteValue; end;end;I tried converting the ByteArray in different encodings, but none of them worked as expected:
//UTF-8: TEncoding.UTF8.GetString(ByteArray)//This raised an exception. //ISO-8859-1: TEncoding.GetEncoding(28591).GetString(ByteArray)//This resulted in incorrect content. //Windows-1252: TEncoding.GetEncoding(1252).GetString(ByteArray)//This also resulted in incorrect content. What I Want:
The content I am trying to extract is ZPL (Zebra Programming Language).
If you need more code or details to reproduce the issue, feel free to let me know, and I can share it.