Json and Bson convert to each other.
More...
#include "cJSON.h"
#include "bson/bson.h"
Go to the source code of this file.
|
#define | JSON_DECIMAL_NO_CONVERT 0 |
|
#define | JSON_DECIMAL_TO_DOUBLE 1 |
|
#define | JSON_DECIMAL_TO_STRING 2 |
|
#define | JSON_FLAG_CHECK_END 0x00000001 |
|
#define | JSON_FLAG_ESCAPE_UNICODE 0x00000002 |
|
#define | JSON_FLAG_APPEND_OID 0x00000004 |
|
#define | JSON_FLAG_NOT_INIT_BSON 0x00000008 |
|
#define | JSON_FLAG_RIGOROUS_MODE 0x00000010 |
|
#define | JSON_FLAG_DECIMAL_TO_DOUBLE 0x00000020 |
|
#define | JSON_FLAG_DECIMAL_TO_STRING 0x00000040 |
|
|
SDB_EXPORT void | JsonSetPrintfLog (void(*pFun)(const CHAR *pFunc, const CHAR *pFile, UINT32 line, const CHAR *pFmt,...)) |
|
SDB_EXPORT BOOLEAN | jsonToBson (bson *bs, const CHAR *json_str) |
|
SDB_EXPORT BOOLEAN | jsonToBson2 (bson *bs, const CHAR *json_str, BOOLEAN isMongo, BOOLEAN isBatch) |
|
SDB_EXPORT BOOLEAN | json2bson2 (const CHAR *pJson, bson *pBson) |
| Json converts to bson.
|
|
SDB_EXPORT BOOLEAN | json2bson (const CHAR *pJson, CJSON_MACHINE *pMachine, INT32 parseMode, BOOLEAN isCheckEnd, BOOLEAN isUnicode, INT32 decimalto, bson *pBson) |
|
SDB_EXPORT BOOLEAN | json2bson3 (const CHAR *pJson, CJSON_MACHINE *pMachine, INT32 flags, bson *pBson) |
| Json converts to bson.
|
|
SDB_EXPORT void | setJsonPrecision (const CHAR *pFloatFmt) |
|
SDB_EXPORT BOOLEAN | bsonToJson (CHAR *buffer, INT32 bufsize, const bson *b, BOOLEAN toCSV, BOOLEAN skipUndefined) |
| Bson converts to json.
|
|
SDB_EXPORT BOOLEAN | bsonToJson2 (CHAR *buffer, INT32 bufsize, const bson *b, BOOLEAN isStrict) |
| Bson converts to json.
|
|
Json and Bson convert to each other.
BOOLEAN bsonToJson |
( |
CHAR * |
buffer, |
|
|
INT32 |
bufsize, |
|
|
const bson * |
b, |
|
|
BOOLEAN |
toCSV, |
|
|
BOOLEAN |
skipUndefined |
|
) |
| |
Bson converts to json.
- Parameters
-
[in] | buffer | the buffer to convert |
[in] | bufsize | the buffer's size |
[in] | b | The bson object to convert |
[in] | toCSV | bson to csv or not |
[in] | skipUndefined | to skip undefined filed or not |
[out] | buffer | The return json string |
- Return values
-
TRUE | Operation Success |
FALSE | Operation Fail |
- Note
- Before calling this funtion,need to build up a buffer for the convertion result.
BOOLEAN bsonToJson2 |
( |
CHAR * |
buffer, |
|
|
INT32 |
bufsize, |
|
|
const bson * |
b, |
|
|
BOOLEAN |
isStrict |
|
) |
| |
Bson converts to json.
- Parameters
-
[in] | buffer | the buffer to convert |
[in] | bufsize | the buffer's size |
[in] | b | The bson object to convert |
[in] | isStrict | Strict export of data types |
[out] | buffer | The return json string |
- Return values
-
TRUE | Operation Success |
FALSE | Operation Fail |
- Note
- Before calling this funtion,need to build up a buffer for the convertion result.
BOOLEAN json2bson2 |
( |
const CHAR * |
pJson, |
|
|
bson * |
pBson |
|
) |
| |
Json converts to bson.
- Parameters
-
[in] | pJson | The json string to convert |
[out] | pBson | The return bson object |
- Return values
-
TRUE | Operation Success |
FALSE | Operation Fail |
BOOLEAN json2bson3 |
( |
const CHAR * |
pJson, |
|
|
CJSON_MACHINE * |
pMachine, |
|
|
INT32 |
flags, |
|
|
bson * |
pBson |
|
) |
| |
Json converts to bson.
- Parameters
-
[in] | pJson | The json string to convert |
[in] | pMachine | The json parse state machine |
[in] | flags | Converted parameters JSON_FLAG_CHECK_END: Check the characters behind json JSON_FLAG_ESCAPE_UNICODE: Escape Unicode encoding JSON_FLAG_APPEND_OID: Append the _id field JSON_FLAG_NOT_INIT_BSON: Do not initialize bson JSON_FLAG_RIGOROUS_MODE: Strictly parse json format JSON_FLAG_DECIMAL_TO_DOUBLE: Decimal forced conversion to double JSON_FLAG_DECIMAL_TO_STRING: Decimal forced conversion to string |
[out] | pBson | The return bson object |
- Return values
-
TRUE | Operation Success |
FALSE | Operation Fail |