Difference between revisions of "IoTGateway/AdvJSON"

From ESS-WIKI
Jump to: navigation, search
(What is JSON?)
(C functions)
Line 6: Line 6:
  
 
=C functions=
 
=C functions=
 +
==List==
 +
<source lang="C">int JSON_Validator(const char *json);</source>
 +
''Description''
 +
*This function validates a string in JSON format.
 +
''Parameters''
 +
* json [POINTER]
 +
**a string.
 +
''Return Values''
 +
*[0|1] Error or Success.
 +
<br>
 +
----
 +
<br>
 +
<source lang="C">JSONode *JSON_Parser(const char *json);</source>
 +
''Description''
 +
*Translate a string into a tree structure pointer(JSONode);
 +
''Parameters''
 +
* json [POINTER]
 +
**a string.
 +
''Return Values''
 +
*(JSONode *)
 +
** A pointer describes a JSON tree structure.
 +
<br>
 +
----
 +
<br>
 +
<source lang="C">void JSON_Destory(JSONode **json);</source>
 +
''Description''
 +
*Destory a JSON tree sturcture;
 +
''Parameters''
 +
* json [POINTER]
 +
**double-pointer of JSON tree sturcture.
 +
''Return Values''
 +
*None
 +
<br>
 +
----
 +
<br>
 +
<source lang="C">JSONode *JSON_Copy(JSONode *json);</source>
 +
''Description''
 +
*Copy a JSON tree sturcture into another pointer.
 +
''Parameters''
 +
* json [POINTER]
 +
**source pointer
 +
''Return Values''
 +
*(JSONode *)
 +
** result pointer
 +
<br>
 +
----
 +
<br>
 +
<source lang="C">void JSON_Get(JSONode *json, const char *path, char *result, int size);</source>
 +
''Description''
 +
*A Structured-Path-Query function.
 +
''Parameters''
 +
* json [POINTER]
 +
**source.
 +
*path [POINTER]
 +
**a structure-path string
 +
*result [POINTER]
 +
** result string
 +
*size [NUMBER]
 +
** the size of result.
 +
''Return Values''
 +
*None
 +
''Example''
 +
<source lang="C">
 +
char result[256];
 +
JSON_Get(json, "[a][b][c][d]", result, 256);
 +
JSON_Get(json, "/a/b/c/d", result, 256);
 +
</source>
 +
<br>
 +
----
 +
<br>
 +
<source lang="C">void JSON_Cmd(JSONode *json, const char *path, char *assign, int size);</source>
 +
''Description''
 +
*A Command-line-like function.
 +
''Parameters''
 +
* json [POINTER]
 +
**source.
 +
*path [POINTER]
 +
**a command string
 +
*assign[POINTER]
 +
** target
 +
*size [NUMBER]
 +
** the size of target.
 +
''Return Values''
 +
*None
 +
''Example''
 +
<source lang="C">
 +
JSON_Cmd(json, "New [a][b][c][d]", "123", 3);
 +
JSON_Cmd(json, "POST /a/b/c/d", "123", 3);
 +
</source>
 +
 
=C++=
 
=C++=
 
==Fundamental==
 
==Fundamental==

Revision as of 06:46, 23 February 2016

What is JSON?

  • JSON stands for JavaScript Object Notation
  • JSON is a lightweight data-interchange format
  • JSON is language independent
  • JSON is "self-describing" and easy to understand

C functions

List

int JSON_Validator(const char *json);

Description

  • This function validates a string in JSON format.

Parameters

  • json [POINTER]
    • a string.

Return Values

  • [0|1] Error or Success.




JSONode *JSON_Parser(const char *json);

Description

  • Translate a string into a tree structure pointer(JSONode);

Parameters

  • json [POINTER]
    • a string.

Return Values

  • (JSONode *)
    • A pointer describes a JSON tree structure.




void JSON_Destory(JSONode **json);

Description

  • Destory a JSON tree sturcture;

Parameters

  • json [POINTER]
    • double-pointer of JSON tree sturcture.

Return Values

  • None




JSONode *JSON_Copy(JSONode *json);

Description

  • Copy a JSON tree sturcture into another pointer.

Parameters

  • json [POINTER]
    • source pointer

Return Values

  • (JSONode *)
    • result pointer




void JSON_Get(JSONode *json, const char *path, char *result, int size);

Description

  • A Structured-Path-Query function.

Parameters

  • json [POINTER]
    • source.
  • path [POINTER]
    • a structure-path string
  • result [POINTER]
    • result string
  • size [NUMBER]
    • the size of result.

Return Values

  • None

Example

char result[256];
JSON_Get(json, "[a][b][c][d]", result, 256);
JSON_Get(json, "/a/b/c/d", result, 256);




void JSON_Cmd(JSONode *json, const char *path, char *assign, int size);

Description

  • A Command-line-like function.

Parameters

  • json [POINTER]
    • source.
  • path [POINTER]
    • a command string
  • assign[POINTER]
    • target
  • size [NUMBER]
    • the size of target.

Return Values

  • None

Example

JSON_Cmd(json, "New [a][b][c][d]", "123", 3);
JSON_Cmd(json, "POST /a/b/c/d", "123", 3);

C++

Fundamental

Erase & Delete

Operation

Creator

Example