You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: source files in "src/exiforjson" and "src/json" are meant to show a mapping between textual JSON and EXIforJSON (and vice-versa).
Constrained implementations are encouraged to use code in "src/codec" only by using the streaming API in a datatyped manner.
Demo program
Sample program to illustrate how to write EXIforJSON and read JSON again
#include<stdio.h>#include<stdlib.h>#include<string.h>#include"EXIforJSONEncoder.h"#include"EXIforJSONDecoder.h"#defineBUFFER_SIZE 8192
intmain(intargc, char*argv[]) {
interrn=0;
char*JSON_STRING_IN="{\"keyNumber\": 123, \"keyArrayStrings\": [ \"s1\", \"s2\" ] }";
constsize_tlenOut=strlen(JSON_STRING_IN) +100; /* some extra space for decoding differences e.g, number 1 -> 1E0 etc */charJSON_STRING_OUT[lenOut];
uint8_tbuffer[BUFFER_SIZE];
size_tposEncode=0;
size_tposDecode=0;
printf("FROM: \n%s \n", JSON_STRING_IN);
errn=encodeEXIforJSON(JSON_STRING_IN, strlen(JSON_STRING_IN), buffer, BUFFER_SIZE, &posEncode);
if( errn==0 ) {
/* OK so far */printf("Encoding JSON (len=%d) to EXIforJSON (len=%d) was successful \n", strlen(JSON_STRING_IN), posEncode);
/* Try to transform it back to JSON again */errn=decodeEXIforJSON(buffer, BUFFER_SIZE, &posDecode, JSON_STRING_OUT, lenOut);
if( errn==0 ) {
/* OK */printf("Decoding EXIforJSON (len=%d) to JSON (len=%d) was successful \n", posEncode, strlen(JSON_STRING_OUT));
printf("TO: \n%s \n", JSON_STRING_OUT);
} else {
/* ERROR */printf("Decoding EXIforJSON to JSON failed due to error %d \n", errn);
}
} else {
/* ERROR */printf("Encoding JSON to EXIforJSON failed due to error %d \n", errn);
}
returnerrn;
}