c3e272aaf11a7a249ca8d110641c074e3d9d7fbb
+ harbour/src/rtl/hbjson.c
+ added JavaScript Object Notation (JSON) encoder, decoder functions
; C level functions:
char * hb_jsonEncode( PHB_ITEM pValue, HB_SIZE * pnLen );
pValue - value to encode;
pnLen - if pnLen is not NULL, length of returned buffer is
stored to *pnLen;
returns pointer to encoded JSON buffer. buffer must be fried
by the caller.
HB_SIZE hb_jsonDecode( const char * szSource, PHB_ITEM pValue );
szSource - JSON source;
pValue - item to store decoded value. Item value is
undetermined in case of error;
returns number of bytes decoded from the buffer. This allows
to use the remaining part of the buffer for some other
purposes. Returns 0 on error.
Harbour level functions:
hb_jsonDecode( cJSON, @xValue ) --> nLengthDecoded
hb_jsonEncode( xValue ) --> cJSON
Note:
- Harbour types unsupported by JSON (date, timestamp, etc.) are
encoded as null values;
- strings are encoded in UTF-8;
- JSON encode functions are safe for recursive arrays and hashes.
Recursive part of array or hash will be stored as null. JSON
encoder still allows to use same structure in the leaves, in
this case content will be duplicate.
I.e.:
xI := {1, NIL}
xI[2] := xI
? hb_jsonEncode( xI ) // [1,null]
but:
xI := {1, .T.}
xI := {2, xI, xI}
? hb_jsonEncode( xI ) // [2,[1,true],[1,true]]
Description
Harbour Core — Reference source for Five development
Languages
C
80.3%
xBase
17.8%
Makefile
0.6%
C++
0.4%
Harbour
0.4%
Other
0.3%