SequoiaDB
 All Classes Files Functions Variables Enumerations Enumerator
Macros | Functions
jstobs.h File Reference

Json and Bson convert to each other. More...

#include "cJSON.h"
#include "bson/bson.h"

Go to the source code of this file.

Macros

#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
 

Functions

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.
 

Detailed Description

Json and Bson convert to each other.

Function Documentation

BOOLEAN bsonToJson ( CHAR *  buffer,
INT32  bufsize,
const bson b,
BOOLEAN  toCSV,
BOOLEAN  skipUndefined 
)

Bson converts to json.

Parameters
[in]bufferthe buffer to convert
[in]bufsizethe buffer's size
[in]bThe bson object to convert
[in]toCSVbson to csv or not
[in]skipUndefinedto skip undefined filed or not
[out]bufferThe return json string
Return values
TRUEOperation Success
FALSEOperation 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]bufferthe buffer to convert
[in]bufsizethe buffer's size
[in]bThe bson object to convert
[in]isStrictStrict export of data types
[out]bufferThe return json string
Return values
TRUEOperation Success
FALSEOperation 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]pJsonThe json string to convert
[out]pBsonThe return bson object
Return values
TRUEOperation Success
FALSEOperation Fail
BOOLEAN json2bson3 ( const CHAR *  pJson,
CJSON_MACHINE *  pMachine,
INT32  flags,
bson pBson 
)

Json converts to bson.

Parameters
[in]pJsonThe json string to convert
[in]pMachineThe json parse state machine
[in]flagsConverted 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]pBsonThe return bson object
Return values
TRUEOperation Success
FALSEOperation Fail