cJSON Data Structure

<< Click to Display Table of Contents >>

Navigation:  ThinBASIC Modules > cJSON > CJSon low level interface >

cJSON Data Structure

 

Description

 

cJSON structure.

 

This UDT (User Defined Type) is the core of cJSON module.

Almost every function of this module needs a cJSON UDT pointer in input or return a cJSON UDT pointer as output.

 

Syntax

 

Type cJSON

  pNext        As cJSON PTR  '---Pointer to the next sibling element

  pPrev        As cJSON PTR  '---Pointer to the previous sibling element

  pChild       As cJSON PTR  '---Pointer to child element

 

  lType        As Long       '---Element type

 

  valueString  As ASCIIZ PTR '---When lType is %cJSON_IsString this point to its value 

  valueInt     As Long       '---When lType is %cJSON_IsNumber this represent its integer value

  valueDouble  As Double     '---When lType is %cJSON_IsNumber this represent its value

 

  pString      As ASCIIZ PTR '---Name of the JSON element

End Type

 

Remarks

 

cJSON structure represent a JSON element.

More elements are connected each other using a double linked list of elements (pNext and pPrev).

Objects and Arrays have a pChild element that is the head of a double linked list.

 

By default all values are 0 unless set by virtue of being meaningful.

 

pNext/pPrev is a doubly linked list of siblings. pNext takes you to your sibling, pPrev takes you back from your sibling to you.

Only objects and arrays have a pChild, and it's the head of the doubly linked list.

A pChild entry will have prev == 0, but pNext potentially points on.

The last sibling has pNext == 0.

 

The lType expresses Null/True/False/Number/String/Array/Object, all of which have a corresponding cJSON_Is* function

 

A Number has valueint and valuedouble. valueint is a relict of the past, so always use valuedouble.

 

Any entry which is in the linked list which is the child of an object will have a string which is the "name" of the entry. When I said "name" in the above example, that's string. string is the JSON name for the 'variable name' if you will.

 

Now you can trivially walk the lists, recursively, and parse as you please.

You can invoke cJSON_Parse to get cJSON to parse for you, and then you can take the root object, and traverse the structure (which is, formally, an N-tree), and tokenise as you please.

 

See also

 

Examples