INGOR
|
JSON parser, writer and Simple Print API. More...
Public Member Functions | |
ytObject * | ytJSON_parse (FILE *fp, int opt) |
Parses JSON format data from file stream. | |
ytObject * | ytJSON_parseStr (const char *str) |
Parses JSON format data from a string. | |
void | ytJSON_printDouble (FILE *fp, double v) |
Prints the double value as a JSON-complied expression. | |
void | ytJSON_print (FILE *fp, const ytObject *obj, int opt) |
Prints an ytObject instance in JSON format into the stream. | |
ytJSON_SP * | ytJSON_SP_new (FILE *fp, int readable) |
Initializes the Simple Print API of JSON. | |
void | ytJSON_SP_delete (ytJSON_SP *work) |
Finishes the outputting using Simple Print API. | |
void | ytJSON_SP_beginObject (ytJSON_SP *work) |
Begins a new object block. | |
void | ytJSON_SP_endObject (ytJSON_SP *work) |
Ends a object block. | |
void | ytJSON_SP_beginArray (ytJSON_SP *work) |
Begins a new array. | |
void | ytJSON_SP_endArray (ytJSON_SP *work) |
Ends a definition of array. | |
void | ytJSON_SP_putStr (ytJSON_SP *work, const char *name, const char *value) |
Puts a string value with its name. | |
void | ytJSON_SP_putInt (ytJSON_SP *work, const char *name, int value) |
Puts an integer value with its name. | |
void | ytJSON_SP_putDouble (ytJSON_SP *work, const char *name, double value) |
Puts a double value with its name. | |
void | ytJSON_SP_putDoubleArray (ytJSON_SP *work, const char *name, const ytDoubleArray *value) |
Puts a double array value with its name. | |
void | ytJSON_SP_putIntArray (ytJSON_SP *work, const char *name, const ytIntArray *value) |
Puts a integer array value with its name. | |
void | ytJSON_SP_putStrArray (ytJSON_SP *work, const char *name, const ytStrArray *value) |
Puts a string array value with its name. | |
void | ytJSON_SP_putObject (ytJSON_SP *work, const char *name) |
Puts an object with its name. | |
void | ytJSON_SP_putArray (ytJSON_SP *work, const char *name) |
Puts an array with its name. | |
Related Symbols | |
(Note that these are not member symbols.) | |
#define | ytJSON_OPT_HYPHEN_BREAK |
Constant value for the option in ytJSON_parse(). | |
#define | ytJSON_OPT_FORMAT |
Constant value for the option in ytJSON_print(). | |
JSON parser, writer and Simple Print API.
This provides funtions for reading and outputing with JSON format. For outputing there are two types of interface: one for outputing a ytKeyValues object as JSON, one for outputing without using a ytKeyValues object.
This is an example of the code.
If you want to output the above JSON object, write code as below.
ytObject * ytJSON_parse | ( | FILE * | fp, |
int | opt ) |
Parses JSON format data from file stream.
An object containing pairs of name-values is returned as ytKeyValues instance.
An array is converted to an instance of ytArray.
Any numerical value is converted to a double precision floating point value as an ytValue object with the ytType_DOUBLE type.
A Boolean value is converted to an integer value as an ytValue object with the ytType_INT type.
A null value is return as ytType_NULL value in a ytValue object.
Some optional settings can be accepted. Currently, only ytJSON_OPT_HYPHEN_BREAK is suppoted.
fp | FILE stream. |
opt | 0 or ytJSON_OPT_HYPHEN_BREAK for enabling stopping parsing if a line with only "- " is found. |
ytObject * ytJSON_parseStr | ( | const char * | str | ) |
Parses JSON format data from a string.
See ytJSON_parse() for details.
void ytJSON_print | ( | FILE * | fp, |
const ytObject * | obj, | ||
int | opt ) |
Prints an ytObject instance in JSON format into the stream.
The object can contain only ytKeyValues, ytType_INT, ytType_DOUBLE, ytType_CHAR_P (string), and ytArray instances.
Numerical values need to be ytType_DOUBLE values. ytType_INT values are regarded as Boolean values.
obj | ytObject instance to print. |
fp | FILE pointer. |
opt | 0 or ytJSON_OPT_FORMAT for printing with human friendly formattings. |
void ytJSON_printDouble | ( | FILE * | fp, |
double | v ) |
Prints the double value as a JSON-complied expression.
An infinity value is printed as "1e999999" or "-1e999999", and these expression will be parsed as an infinity when parsing.
A NaN value is printed as "null".
fp | FILE pointer |
v | double value to print. |
void ytJSON_SP_beginArray | ( | ytJSON_SP * | work | ) |
Begins a new array.
Users mus call ytJSON_SP_endArray() to tell the end of the array definition. To output elements of the array, simply call put functions such as ytJSON_SP_putStr().
work | pointer to the ytJSON_SP instance. |
void ytJSON_SP_beginObject | ( | ytJSON_SP * | work | ) |
Begins a new object block.
Users must call ytJSON_SP_endObject() to tell the end of object definition. Here an object block refers to an object defined as a pair of braces: {
and }
in JSON.
work | pointer to the ytJSON_SP instance. |
void ytJSON_SP_delete | ( | ytJSON_SP * | work | ) |
Finishes the outputting using Simple Print API.
If the number of end functions such as ytJSON_SP_endObject() called is not enough for begin functions, then this automatically ends the particular object or array definition blocks.
work | pointer to the ytJSON_SP object. |
void ytJSON_SP_endArray | ( | ytJSON_SP * | work | ) |
Ends a definition of array.
work | pointer to the ytJSON_SP instance. |
void ytJSON_SP_endObject | ( | ytJSON_SP * | work | ) |
Ends a object block.
work | pointer to the ytJSON_SP instance. |
ytJSON_SP * ytJSON_SP_new | ( | FILE * | fp, |
int | readable ) |
Initializes the Simple Print API of JSON.
fp | File pointer to output. |
readable | Set 1 if indentation is enabled for human readablility. This increases the file size. |
void ytJSON_SP_putArray | ( | ytJSON_SP * | work, |
const char * | name ) |
Puts an array with its name.
This begins a new array block. Therefore, users must close the array definition by ytJSON_SP_endArray() after putting all the elements of the array you want to put.
name | name of a value to output. |
void ytJSON_SP_putDouble | ( | ytJSON_SP * | work, |
const char * | name, | ||
double | value ) |
Puts a double value with its name.
work | |
name | |
value |
void ytJSON_SP_putDoubleArray | ( | ytJSON_SP * | work, |
const char * | name, | ||
const ytDoubleArray * | value ) |
Puts a double array value with its name.
work | |
name | |
value |
void ytJSON_SP_putInt | ( | ytJSON_SP * | work, |
const char * | name, | ||
int | value ) |
Puts an integer value with its name.
work | |
name | |
value |
void ytJSON_SP_putIntArray | ( | ytJSON_SP * | work, |
const char * | name, | ||
const ytIntArray * | value ) |
Puts a integer array value with its name.
work | |
name | |
value |
void ytJSON_SP_putObject | ( | ytJSON_SP * | work, |
const char * | name ) |
Puts an object with its name.
This begins a new object block. Therefore, users must close the object definition by ytJSON_SP_endObject() after putting the pairs of names and their values.
name | name of a value to output. |
void ytJSON_SP_putStr | ( | ytJSON_SP * | work, |
const char * | name, | ||
const char * | value ) |
Puts a string value with its name.
work | pointer to the ytJSON_SP instance. |
name |
void ytJSON_SP_putStrArray | ( | ytJSON_SP * | work, |
const char * | name, | ||
const ytStrArray * | value ) |
Puts a string array value with its name.
work | |
name | |
value |