Unicode C
Unicode C
Extract PDF from JSON
See more JSON Examples
Demonstrates how to extract a PDF file contained within JSON. The file is represented as a base64 string within the JSON. Note: This example can extract any type of file, not just a PDF file.Chilkat Unicode C Downloads
#include <C_CkJsonObjectW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkBinDataW.h>
void ChilkatSample(void)
{
BOOL success;
HCkJsonObjectW json;
HCkStringBuilderW sb;
HCkBinDataW bd;
success = FALSE;
json = CkJsonObjectW_Create();
// Load the JSON.
success = CkJsonObjectW_LoadFile(json,L"qa_data/json/JSR5U.json");
if (success != TRUE) {
wprintf(L"%s\n",CkJsonObjectW_lastErrorText(json));
CkJsonObjectW_Dispose(json);
return;
}
// The JSON we loaded contains this:
// {
// ...
// ...
// "data": {
// "content": "JVBERi0xLjQ..."
// }
// ...
// ...
// }
sb = CkStringBuilderW_Create();
CkJsonObjectW_StringOfSb(json,L"data.content",sb);
bd = CkBinDataW_Create();
CkBinDataW_AppendEncodedSb(bd,sb,L"base64");
success = CkBinDataW_WriteFile(bd,L"qa_output/a0015.pdf");
CkJsonObjectW_Dispose(json);
CkStringBuilderW_Dispose(sb);
CkBinDataW_Dispose(bd);
}