Unicode C
Unicode C
JSON Hex Encoding
See more JSON Examples
Let's say your JSON contains content that is hex encoded like this: \u05d1\u05d3\u05d9\u05e7This example shows how to get the decoded string.
Chilkat Unicode C Downloads
#include <C_CkJsonObjectW.h>
#include <C_CkStringBuilderW.h>
void ChilkatSample(void)
{
BOOL success;
const wchar_t *s;
HCkJsonObjectW json;
HCkStringBuilderW sb;
success = FALSE;
s = L"{ \"example\": \"\\u05d1\\u05d3\\u05d9\\u05e7\" }";
json = CkJsonObjectW_Create();
success = CkJsonObjectW_Load(json,s);
// When getting the member data, it is automatically decoded.
wprintf(L"member data: %s\n",CkJsonObjectW_stringOf(json,L"example"));
// Output:
// member data: בדיק
// When getting the full JSON, it remains encoded. This is expected and intentional.
wprintf(L"full JSON: %s\n",CkJsonObjectW_emit(json));
// Output:
// full JSON: {"example":"\u05d1\u05d3\u05d9\u05e7"}
// To get the full JSON without the encoding, you can decode manually.
sb = CkStringBuilderW_Create();
CkJsonObjectW_EmitSb(json,sb);
// The hex encoding used by JSON is utf-8.
CkStringBuilderW_Decode(sb,L"json",L"utf-8");
wprintf(L"%s\n",CkStringBuilderW_getAsString(sb));
// Output:
// {"example":"בדיק"}
CkJsonObjectW_Dispose(json);
CkStringBuilderW_Dispose(sb);
}