Kii JSON
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
Public Attributes | List of all members
kii_json_field_t Struct Reference

#include <kii_json.h>

Public Attributes

const char * name
 
const char * path
 
kii_json_field_parse_result_t result
 
kii_json_field_type_t type
 
size_t start
 
size_t end
 
union {
   char *   string
 
   int   int_value
 
   long   long_value
 
   double   double_value
 
   kii_json_boolean_t   boolean_value
 
field_copy
 
size_t field_copy_buff_size
 

Detailed Description

JSON parsed field data.

Input of kii_json_read_object(kii_json_t*, const char*, size_t, kii_json_field_t*).

Array of kii_json_field_t is passed to kii_json_read_object(kii_json_t*, const char*, size_t, kii_json_field_t*).

End point of the array is specified by kii_json_field_t::name and kii_json_field_t::path. If both of kii_json_field_t::name and kii_json_field_t::path are NULL, kii_json_read_object(kii_json_t*, const char*, size_t, kii_json_field_t*) consider that it is the end point of the passed array.

Member Data Documentation

kii_json_boolean_t kii_json_field_t::boolean_value

This value is used if kii_json_field_t::type is kii_json_field_type_t::KII_JSON_FIELD_TYPE_BOOLEAN.

double kii_json_field_t::double_value

This value is used if kii_json_field_t::type is kii_json_field_type_t::KII_JSON_FIELD_TYPE_DOUBLE. If parsing target is overflowed, then this value is plus or minus HUGE_VAL. If parsing is underflowed, then this value is 0.

size_t kii_json_field_t::end

End point of this field in given buffer. Output of kii_json_read_object(kii_json_t*, const char*, size_t, kii_json_field_t*).

union { ... } kii_json_field_t::field_copy

Buffer to copy field value. if NULL, no copy is generated. Using value is determined by value of kii_json_field_t::type. If kii_json_field_t::type is kii_json_field_type_t::KII_JSON_FIELD_TYPE_NULL, no copy is generated.

size_t kii_json_field_t::field_copy_buff_size

Length of field_copy::string. ignored if field_copy::string is null or kii_json_field_t::type is not kii_json_field_type_t::KII_JSON_FIELD_TYPE_STRING, kii_json_field_type_t::KII_JSON_FIELD_TYPE_OBJECT and kii_json_field_type_t::KII_JSON_FIELD_TYPE_ARRAY.

int kii_json_field_t::int_value

This value is used if kii_json_field_t::type is kii_json_field_type_t::KII_JSON_FIELD_TYPE_INTEGER. If parsing target is overflowed, then this value is INT_MAX. If parsing is underflowed, then this value is INT_MIN.

long kii_json_field_t::long_value

This value is used if kii_json_field_t::type is kii_json_field_type_t::KII_JSON_FIELD_TYPE_LONG. If parsing target is overflowed, then this value is LONG_MAX. If parsing is underflowed, then this value is LONG_MIN.

const char* kii_json_field_t::name

Parsing target key name. Input of kii_json_read_object(kii_json_t*, const char*, size_t, kii_json_field_t*).

This can point an only field in root json object.

Deprecated:
{You should use kii_json_field_t::path}
const char* kii_json_field_t::path

Parsing target path. Input of kii_json_read_object(kii_json_t*, const char*, size_t, kii_json_field_t*).

This can point any field or element of array. BNF like notation of path is following:

path ::= '/' identifier subpath
subpath ::= '/' identifier subpath | ''
identifier ::= field | index
index ::= '[' 0 ']' | '[' [1-9][0-9]+ ']'
field ::= [char | escaped]+
char ::= any ascii characters expect '/', '[', ']' and '\'
escaped = "\\/" | "\\[" | "\\]" | "\\"

If you want to get first element of color array in following json example:

{
"ligtht" : {
"color" : [ 0, 128, 255]
}
}
path ="/ligtht/color/[0]";

In rare cases, like following:

{
"[]/\\" : "rare"
}

You can specify "[]/\\" as following:

path ="/\\[\\]\\/\\";
kii_json_field_parse_result_t kii_json_field_t::result

Field parse result. Output of kii_json_read_object(kii_json_t*, const char*, size_t, kii_json_field_t*).

size_t kii_json_field_t::start

Start point of this field in given buffer. Output of kii_json_read_object(kii_json_t*, const char*, size_t, kii_json_field_t*).

char* kii_json_field_t::string

This value is used if kii_json_field_t::type is kii_json_field_type_t::KII_JSON_FIELD_TYPE_STRING, kii_json_field_type_t::KII_JSON_FIELD_TYPE_OBJECT or kii_json_field_type_t::KII_JSON_FIELD_TYPE_ARRAY.

kii_json_field_type_t kii_json_field_t::type

Parsed target value type. Input and Output of kii_json_read_object(kii_json_t*, const char*, size_t, kii_json_field_t*). Inputted value is expected value type and outputted value is actual value type.

If type is set as kii_json_field_type_t::KII_JSON_FIELD_TYPE_ANY, then kii_json_read_object(kii_json_t*, const char*, size_t, kii_json_field_t*) ignore type checking.

If actual type is not matched expected type:

  • kii_json_read_object(kii_json_t*, const char*, size_t, kii_json_field_t*) set actual type.
  • if expected type is not kii_json_field_type_t::KII_JSON_FIELD_TYPE_ANY, then kii_json_field_t::result becomes kii_json_parse_result_t::KII_JSON_FIELD_PARSE_TYPE_UNMATCHED.
  • if expected type is kii_json_field_type_t::KII_JSON_FIELD_TYPE_ANY, then kii_json_field_t::result become kii_json_parse_result_t::KII_JSON_FIELD_PARSE_SUCCESS.

The documentation for this struct was generated from the following file: