本文整理汇总了C++中cJSON_CreateObject函数的典型用法代码示例。如果您正苦于以下问题:C++ cJSON_CreateObject函数的具体用法?C++ cJSON_CreateObject怎么用?C++ cJSON_CreateObject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cJSON_CreateObject函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createServerUserFindUser
int createServerUserFindUser(int sock,int clienttype,user_info_t* userinfo){
client_header_2_t* header = createClientHeader(COMMAND_OTHER_MESSAGE,MESSAGE_TYPE_USER_LOGIN,clienttype);
cJSON* json = cJSON_CreateObject();
if(userinfo != NULL){
cJSON_AddStringToObject(json,"username",userinfo->username);
cJSON_AddStringToObject(json,"userid",userinfo->userid);
cJSON_AddNumberToObject(json,"isSuccess",1);
cJSON* arr = cJSON_CreateArray();
if(userinfo->drivces){
list_node_t* node = NULL;
int i = 0;
for(i=0;i<userinfo->drivces->len;i++)
{
node = list_at(userinfo->drivces,i);
printf("pop list=%s\n",node->val);
cJSON_AddItemToArray(arr,cJSON_CreateString(node->val));
}
}
cJSON_AddItemToObject(json,"driveces",arr);
}
else{
cJSON_AddNumberToObject(json,"isSuccess",0);
}
char* str = cJSON_Print(json);
printf("%s,%d",str,strlen(str));
int total = sizeof(server_header_2_t)+sizeof(uint16_t)+strlen(str);
void* bufs = malloc(total);
void* buf = bufs;
header->total = total;
memcpy(buf,header,sizeof(server_header_2_t));
buf += sizeof(server_header_2_t);
*(uint16_t*)buf = htons(strlen(str));
buf += sizeof(uint16_t);
memcpy(buf,str,strlen(str));
int ret =send(sock,bufs,total,0);
free(bufs);
cJSON_Delete(json);
//free(str);
return ret;
}
示例2: cJSON_CreateObject
void CRedWoodDataParse::testAddSensorData()
{
FILE *f;long len;char *data;
f=fopen("json.dat","rb");fseek(f,0,SEEK_END);len=ftell(f);fseek(f,0,SEEK_SET);
data=(char*)malloc(len+1);fread(data,1,len,f);fclose(f);
char *out;cJSON *json, *newjson;
json=cJSON_Parse(data);
newjson = cJSON_CreateObject();
AddSensorDataToJson(cJSON_GetObjectItem(json, "sensorStats"), newjson);
out=cJSON_Print(newjson);
cJSON_Delete(json);
cJSON_Delete(newjson);
printf("%s\n",out);
free(out);
free(data);
}
示例3: LOG_ERROR_FORMAT
bool MSI_SM_Stream::CleanMSIStream(char *strUserId,char *strSerialno)
{
if(!Connect_MSIServer())
{
LOG_ERROR_FORMAT("ERROR - [SM]:%s %d error can't connect to server\n",__FUNCTION__,__LINE__);
return false;
}
if(pRet_root)
{
cJSON_Delete(pRet_root);
pRet_root = NULL;
}
//printf("--begin json\n");
pRet_root = cJSON_CreateObject();
Requst_Json_str(2,"cmd","stream_unbind");
Requst_Json_str(2,"username",strUserId);
Requst_Json_str(2,"serialno",strSerialno);
Send_Jsoon_str();
return true;
}
示例4: synch_create_info
//同步更新,生成info数据
static bool synch_create_info(data_synch_request *data_request) {
cJSON *root;
relater_inf *p = protodata->relaterlist.head;
root = cJSON_CreateArray();
while (p != NULL) {
cJSON *user = cJSON_CreateObject();
cJSON_AddStringToObject(user, SYNCH_INFO_ACCOUNT, p->username);
cJSON_AddNumberToObject(user, SYNCH_INFO_RIGHT, p->right);
cJSON_AddStringToObject(user, SYNCH_INFO_ALIAS, p->alias);
cJSON_AddStringToObject(user, SYNCH_INFO_PASS, p->password);
cJSON_AddNumberToObject(user, SYNCH_INFO_TIME, p->regtime);
cJSON_AddNumberToObject(user, SYNCH_INFO_STATE, p->regstatus);
cJSON_AddItemToArray(root, user);
p = p->next;
}
data_request->json_info = root;
strcpy(data_request->user, protodata->cfg.devname);
data_request->kind = 2;
return true;
}
示例5: joylink_package_subdev
char *
joylink_package_subdev(JLDevInfo_t *sdev, int count)
{
if(NULL == sdev){
return NULL;
}
cJSON *arrary;
char *out = NULL;
unsigned int i;
cJSON **js_devs = (cJSON **)malloc(sizeof(cJSON *) * count);
if(js_devs == NULL){
goto RET;
}
if(NULL == (arrary = cJSON_CreateArray())){
free(js_devs);
goto RET;
}
for(i = 0; i < count; i ++){
js_devs[i] =cJSON_CreateObject();
if(NULL != js_devs[i]){
cJSON_AddItemToArray(arrary, js_devs[i]);
cJSON_AddNumberToObject(js_devs[i], "state", sdev[i].state);
cJSON_AddNumberToObject(js_devs[i], "protocol", sdev[i].jlp.protocol);
cJSON_AddStringToObject(js_devs[i], "mac", sdev[i].jlp.mac);
cJSON_AddStringToObject(js_devs[i], "productuuid", sdev[i].jlp.uuid);
cJSON_AddNumberToObject(js_devs[i], "lancon", sdev[i].jlp.lancon);
cJSON_AddNumberToObject(js_devs[i], "trantype", sdev[i].jlp.cmd_tran_type);
cJSON_AddStringToObject(js_devs[i], "feedid", sdev[i].jlp.feedid);
cJSON_AddStringToObject(js_devs[i], "devkey", sdev[i].jlp.pubkeyS);
}
}
out=cJSON_Print(arrary);
cJSON_Delete(arrary);
RET:
return out;
}
示例6: cJSON_CreateObject
cJSON *InstantDEX_argjson(char *reference,char *message,bits256 basetxid,bits256 reltxid,int32_t iter,int32_t val,int32_t val2)
{
cJSON *argjson = cJSON_CreateObject();
jaddstr(argjson,"ref",reference);
if ( message != 0 && message[0] != 0 )
jaddstr(argjson,"message",message);
jaddbits256(argjson,"basetxid",basetxid);
jaddbits256(argjson,"reltxid",reltxid);
if ( iter != 3 )
{
jaddnum(argjson,"duration",val);
jaddnum(argjson,"flags",val2);
}
else
{
if ( val > 0 )
jaddnum(argjson,"baseheight",val);
if ( val2 > 0 )
jaddnum(argjson,"relheight",val2);
}
return(argjson);
}
示例7: JPLua_Serialiser_CreateRef
// Push a Serialiser instance onto the stack
void JPLua_Serialiser_CreateRef( lua_State *L, const char *path, fsMode_t mode ) {
jplua_serialiser_t *serialiser = NULL;
int len = 0;
serialiser = (jplua_serialiser_t *)lua_newuserdata( L, sizeof(jplua_serialiser_t) );
if (JPLua.currentPlugin){
Com_sprintf(serialiser->fileName, sizeof(serialiser->fileName), "%s%s/%s", pluginDir, JPLua.currentPlugin->name, path);
}
else{
Com_sprintf(serialiser->fileName, sizeof(serialiser->fileName), "%s%s", pluginDir, path);
}
len = trap->FS_Open( serialiser->fileName, &serialiser->fileHandle, mode );
if ( mode == FS_WRITE ) {
serialiser->write = qtrue;
serialiser->read = qfalse;
serialiser->outRoot = cJSON_CreateObject();
}
else if ( mode == FS_READ ) {
serialiser->read = qtrue;
serialiser->write = qfalse;
if ( len > 0 ) {
char *contents = (char *)malloc( len );
trap->FS_Read( contents, len, serialiser->fileHandle );
serialiser->inRoot = cJSON_Parse( contents );
if ( !serialiser->inRoot )
Com_Printf( "Couldn't parse serialised JSON data %s\n", path );
free( contents );
contents = NULL;
}
else
serialiser->inRoot = NULL;
}
luaL_getmetatable( L, SERIALISER_META );
lua_setmetatable( L, -2 );
}
示例8: HASH_AND_INT
HASH_AND_INT(ramchain,getrawtransaction,txid,verbose)
{
struct iguana_txid *tx,T; char *txbytes; bits256 checktxid; int32_t len,height; cJSON *retjson;
if ( (tx= iguana_txidfind(coin,&height,&T,txid)) != 0 )
{
retjson = cJSON_CreateObject();
if ( (len= iguana_txbytes(coin,coin->blockspace,sizeof(coin->blockspace),&checktxid,tx,height,0,0)) > 0 )
{
txbytes = mycalloc('x',1,len*2+1);
init_hexbytes_noT(txbytes,coin->blockspace,len*2+1);
jaddstr(retjson,"result",txbytes);
myfree(txbytes,len*2+1);
return(jprint(retjson,1));
}
else if ( height >= 0 )
{
if ( coin->APIblockstr != 0 )
jaddstr(retjson,"error","already have pending request");
else
{
int32_t datalen; uint8_t *data; char *blockstr; bits256 blockhash;
blockhash = iguana_blockhash(coin,height);
if ( (blockstr= iguana_APIrequest(coin,blockhash,txid,2)) != 0 )
{
datalen = (int32_t)(strlen(blockstr) >> 1);
data = malloc(datalen);
decode_hex(data,datalen,blockstr);
if ( (txbytes= iguana_txscan(coin,verbose != 0 ? retjson : 0,data,datalen,txid)) != 0 )
{
jaddstr(retjson,"result",txbytes);
jaddbits256(retjson,"blockhash",blockhash);
jaddnum(retjson,"height",height);
free(txbytes);
} else jaddstr(retjson,"error","cant find txid in block");
free(blockstr);
free(data);
} else jaddstr(retjson,"error","cant find blockhash");
return(jprint(retjson,1));
}
示例9: azy_content_serialize_request_json
Eina_Bool
azy_content_serialize_request_json(Azy_Content *content)
{
Eina_List *l;
Eina_Value *v;
cJSON *object, *params;
char *msg;
if ((!content) || (content->buffer))
return EINA_FALSE;
object = cJSON_CreateObject();
cJSON_AddStringToObject(object, "method", content->method);
if (content->params)
{
params = cJSON_CreateArray();
EINA_LIST_FOREACH(content->params, l, v)
cJSON_AddItemToArray(params, azy_value_serialize_json(v));
cJSON_AddItemToObject(object, "params", params);
}
cJSON_AddNumberToObject(object, "id", content->id);
if (eina_log_domain_level_check(azy_log_dom, EINA_LOG_LEVEL_DBG))
msg = cJSON_Print(object);
else
msg = cJSON_PrintUnformatted(object);
if(!msg) goto free_object;
azy_content_buffer_set_(content, (unsigned char *)msg, strlen(msg));
cJSON_Delete(object);
return EINA_TRUE;
free_object:
cJSON_Delete(object);
return EINA_FALSE;
}
示例10: util_print_point
void util_print_point(uint32 time, float target, float temperature)
{
cJSON *root;
char *tmpMessage;
sint32 tmp_targ;
sint32 tmp_temp;
tmp_targ = (sint32)( target + 0.5 );
tmp_temp = (sint32)( temperature + 0.5 );
root = cJSON_CreateObject();
cJSON_AddNumberToObject( root, "type", POINT );
cJSON_AddNumberToObject( root, "time", time );
cJSON_AddNumberToObject( root, "target", tmp_targ );
cJSON_AddNumberToObject( root, "temp", tmp_temp );
tmpMessage = cJSON_Print( root );
printf( "%s", tmpMessage );
fflush( stdout );
cJSON_Delete(root);
return;
}
示例11: cJSON_CreateObject
cJSON *JSONNode::spawnNode(int nodeType, char *name)
{
cJSON *node = NULL;
if(nodeType == cJSON_Object) {
node = cJSON_CreateObject();
node -> string = name;
}else if(nodeType == cJSON_Array){
node = cJSON_CreateArray();
node -> string = name;
}else if(nodeType == cJSON_True){
node = cJSON_CreateTrue();
node -> string = name;
}else if(nodeType == cJSON_False){
node = cJSON_CreateFalse();
node -> string = name;
}else if(nodeType == cJSON_NULL){
node = cJSON_CreateNull();
node -> string = name;
}
return node;
}
示例12: Parser_swm_get_smi_rep
int Parser_swm_get_smi_rep(char *pCommData, char **outputStr)
{
sys_mon_info_t * pSysMonInfo = (sys_mon_info_t *)pCommData;
char * out = NULL;
int outLen = 0;
cJSON *pSUSICommDataItem = NULL;
if(pCommData == NULL || outputStr == NULL) return outLen;
pSUSICommDataItem = cJSON_CreateObject();
cJSON_AddSysMonInfoToObject(pSUSICommDataItem, SWM_SYS_MON_INFO, pSysMonInfo);
out = cJSON_PrintUnformatted(pSUSICommDataItem);
outLen = strlen(out) + 1;
*outputStr = (char *)(malloc(outLen));
memset(*outputStr, 0, outLen);
strcpy(*outputStr, out);
cJSON_Delete(pSUSICommDataItem);
printf("%s\n",out);
free(out);
return outLen;
}
示例13: krad_websocket_add_portgroup
void krad_websocket_add_portgroup ( krad_ipc_session_data_t *krad_ipc_session_data, char *portname, float floatval, char *crossfade_name, float crossfade_val, int xmms2 ) {
//printkd ("add a portgroup called %s withe a volume of %f", portname, floatval);
cJSON *msg;
cJSON_AddItemToArray(krad_ipc_session_data->msgs, msg = cJSON_CreateObject());
cJSON_AddStringToObject (msg, "com", "kradmixer");
cJSON_AddStringToObject (msg, "cmd", "add_portgroup");
cJSON_AddStringToObject (msg, "portgroup_name", portname);
cJSON_AddNumberToObject (msg, "volume", floatval);
cJSON_AddStringToObject (msg, "crossfade_name", crossfade_name);
cJSON_AddNumberToObject (msg, "crossfade", crossfade_val);
cJSON_AddNumberToObject (msg, "xmms2", xmms2);
krad_ipc_get_tags (krad_ipc_session_data->krad_ipc_client, portname);
}
示例14: cJSON_CreateObject
cJSON *socket_end_serialize(struct socket_end_st *se) {
cJSON *result, *pipelines;
char keybuf[SHAREDKEY_BYTESIZE*4], byte[8];
int i;
result = cJSON_CreateObject();
pipelines = cJSON_CreateArray();
cJSON_AddNumberToObject(result, "id", se->id);
keybuf[0]=0;
for (i=0;i<SHAREDKEY_BYTESIZE;++i) {
snprintf(byte, 8, "%.2x ", se->shared_key[i]);
strcat(keybuf, byte);
}
cJSON_AddStringToObject(result, "SharedKey", keybuf);
cJSON_AddNumberToObject(result, "SendBuffer", streambuf_nr_bytes(se->send_buffer));
for (i=se->pipeline_1; i!=-1; i=se->pipeline_end[i]->next_id) {
cJSON_AddItemToArray(pipelines, pipeline_end_serialize(se->pipeline_end[i]));
}
cJSON_AddItemToObject(result, "Pipelines", pipelines);
return result;
}
示例15: confirmPathExists
void Cursynth::saveConfiguration() {
confirmPathExists(getConfigPath());
// Store all the MIDI learn data into JSON.
cJSON* root = cJSON_CreateObject();
std::map<int, std::string>::iterator iter = midi_learn_.begin();
for (; iter != midi_learn_.end(); ++iter) {
cJSON* midi = cJSON_CreateNumber(iter->first);
cJSON_AddItemToObject(root, iter->second.c_str(), midi);
}
// Write the configuration JSON to the configuration file.
char* json = cJSON_Print(root);
std::ofstream save_file;
save_file.open(getConfigFile().c_str());
MOPO_ASSERT(save_file.is_open());
save_file << json;
save_file.close();
free(json);
cJSON_Delete(root);
}