(Objective-C) Extract PDF from JSON
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.
#import <CkoJsonObject.h>
#import <CkoStringBuilder.h>
#import <CkoBinData.h>
CkoJsonObject *json = [[CkoJsonObject alloc] init];
// Load the JSON.
BOOL success = [json LoadFile: @"qa_data/json/JSR5U.json"];
if (success != YES) {
NSLog(@"%@",json.LastErrorText);
return;
}
// The JSON we loaded contains this:
// {
// ...
// ...
// "data": {
// "content": "JVBERi0xLjQ..."
// }
// ...
// ...
// }
CkoStringBuilder *sb = [[CkoStringBuilder alloc] init];
[json StringOfSb: @"data.content" sb: sb];
CkoBinData *bd = [[CkoBinData alloc] init];
[bd AppendEncodedSb: sb encoding: @"base64"];
success = [bd WriteFile: @"qa_output/a0015.pdf"];
|