当前位置: 首页>>代码示例>>C++>>正文


C++ cJSON_AddStringToObject函数代码示例

本文整理汇总了C++中cJSON_AddStringToObject函数的典型用法代码示例。如果您正苦于以下问题:C++ cJSON_AddStringToObject函数的具体用法?C++ cJSON_AddStringToObject怎么用?C++ cJSON_AddStringToObject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了cJSON_AddStringToObject函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: cJSON_CreateObject

	void Client::sendChat(std::string str)
	{
        if((_state != ConnectionState::connected) || (_socket == NULL)){
            if(_chatlistener != NULL)
			{
				_chatlistener->onSendChatDone(ResultCode::connection_error);
			}
            return;
        }
		if(str.length() >= 512)
		{
			if(_chatlistener != NULL)
				_chatlistener->onSendChatDone(ResultCode::bad_request);

			return;
		}

		std::string payload;
		int len;

		cJSON *payloadJSON;
		payloadJSON = cJSON_CreateObject();
		cJSON_AddStringToObject(payloadJSON, "chat" ,str.c_str());
		char *cRet = cJSON_PrintUnformatted(payloadJSON);
		payload = cRet;

		byte * req = buildWarpRequest(RequestType::chat, payload, len);

		char *data = new char[len];
		for(int i=0; i< len; ++i)
		{
			data[i] = req[i];
		}

		_socket->sockSend(data, len);

		delete[] data;
		delete[] req;
		cJSON_Delete(payloadJSON);
		free(cRet);
	}
开发者ID:shephertz,项目名称:AppWarpS2Public,代码行数:41,代码来源:appwarp.cpp

示例2: getacc_allmanacc

static bool getacc_allmanacc(data_getacc_reply *data_reply) {
	int count = 0;
	cJSON *root;
	relater_inf *p = protodata->relaterlist.head;

	root = cJSON_CreateArray();

	while (p != NULL) {
		if (p->right == RELATER_AUTHORITY_MAN) {
			cJSON *user = cJSON_CreateObject();
			cJSON_AddStringToObject(user, GETACC_INFO_ACCOUNT, p->username);
			cJSON_AddNumberToObject(user, GETACC_INFO_RIGHT, p->right);
			cJSON_AddItemToArray(root, user);
			count++;
		}
		p = p->next;
	}
	data_reply->json_info = root;
	data_reply->ret = count;
	return true;
}
开发者ID:zhuguoquan45,项目名称:smart,代码行数:21,代码来源:proto_relaterman_start.c

示例3: cJSON_AddNumberToObject

/***************************************************************************
  Function:       package_json_callback 
  Description:    发到5017端口的callback数据格式
  Input:          
                  
  Output:      输出封装好的callback数据的地址   
  Return:       
  Others:         
****************************************************************************/
char *package_json_callback(int type,char *pic_name,int num)
{
    cJSON *root,*fmt;
    char *out;	
    //Our "Video" datatype: 
    root=cJSON_CreateObject();
	cJSON_AddNumberToObject(root,"msgtype",0);
	cJSON_AddNumberToObject(root,"mainid",2);
	cJSON_AddNumberToObject(root,"subid",6);
	cJSON_AddNumberToObject(root,"status",type );
	cJSON_AddNumberToObject(root,"pic_count",num);
	if(type == 0)
	{
		
		cJSON_AddStringToObject(root,"pic_name",pic_name);

	}
    out=cJSON_PrintUnformatted(root);
    cJSON_Delete(root);
    return out; 
}
开发者ID:Jeansfirm,项目名称:glexer-ipc,代码行数:30,代码来源:IPCCapture.c

示例4: cJSON_CreateObject

/*
 * Special properties. This values can modified with the web interface.
 * I.e. angle of kinect, nmbr of areas, position of areas, minimal blob size.
 */
cJSON* PrintSettings::loadDefaults()
{
	cJSON* root = cJSON_CreateObject();	
	cJSON_AddStringToObject(root, "kind", "printSettings");

	cJSON* html = cJSON_CreateArray();	
	cJSON_AddItemToArray(html, jsonIntField("firstLayer",1,1,10000,100) );
	cJSON_AddItemToArray(html, jsonIntField("lastLayer",10000,1,10000,100) );
	cJSON_AddItemToArray(html, jsonDoubleField("normalLayerExposure",12,1,100,10) );
	cJSON_AddItemToArray(html, jsonIntField("nbrAttachLayers",3,1,100,10) );
	cJSON_AddItemToArray(html, jsonDoubleField("attachLayerExposure",60,1,300,10) );

	cJSON_AddItemToObject(root, "html", html);

	/* Point information for repoke 
	cJSON* areas = cJSON_CreateArray();	
	cJSON_AddItemToArray(areas, jsonArea(1,320.0,240.0,100.0) );
	cJSON_AddItemToObject(root, "areas", areas);
	*/
	return root;
}
开发者ID:SHINOTECH,项目名称:TinyPrint,代码行数:25,代码来源:PrintSettings.cpp

示例5: createServerUserLogin

int createServerUserLogin(int sock,int serverid,int isSuccess,char* username){
	server_header_2_t* header = createServerHeader(serverid,COMMAND_OTHER_MESSAGE,MESSAGE_TYPE_USER_LOGIN);
	cJSON* json = cJSON_CreateObject();
	cJSON_AddNumberToObject(json,"result",isSuccess);
	cJSON_AddStringToObject(json,"username",username);	
	//cJSON_AddStringToObject(json,"userid","userid");
	char* str = cJSON_Print(json);	
	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;	
}
开发者ID:zt9788,项目名称:push-server,代码行数:22,代码来源:extended_protocol.c

示例6: createClientUserGetFriends

int createClientUserGetFriends(int sock,int clienttype,char* username){
	client_header_2_t* header = createClientHeader(COMMAND_OTHER_MESSAGE,MESSAGE_TYPE_USER_GET_FRIEND,clienttype);	
	cJSON* json = cJSON_CreateObject();
	cJSON_AddStringToObject(json,"username",username);		
	char* str = cJSON_Print(json);	
	int total = sizeof(client_header_2_t)+sizeof(uint16_t)+strlen(str);
	void* bufs = malloc(total);
	void* buf = bufs;
	header->total = total;
	memcpy(buf,header,sizeof(client_header_2_t));	
	buf += sizeof(client_header_2_t);
	*(uint16_t*)buf = htons(strlen(str));	
	buf += sizeof(uint16_t);
	memcpy(buf,str,strlen(str));
	dump_data(bufs,total);
	int ret =send(sock,bufs,total,0);
	printf("%d\n",ret);
	free(bufs);	
//	free(str);
	cJSON_Delete(json);	
	return ret;	
}
开发者ID:zt9788,项目名称:push-server,代码行数:22,代码来源:extended_protocol.c

示例7: iperf_errexit

/* Do a printf to stderr or log file as appropriate, then exit. */
void
iperf_errexit(struct iperf_test *test, const char *format, ...)
{
    va_list argp;
    char str[1000];

    va_start(argp, format);
    vsnprintf(str, sizeof(str), format, argp);
    if (test != NULL && test->json_output && test->json_top != NULL) {
	cJSON_AddStringToObject(test->json_top, "error", str);
	iperf_json_finish(test);
    } else
	if (test && test->outfile) {
	    fprintf(test->outfile, "iperf3: %s\n", str);
	}
	else {
	    fprintf(stderr, "iperf3: %s\n", str);
	}
    va_end(argp);
    iperf_delete_pidfile(test);
    exit(1);
}
开发者ID:ajaissle,项目名称:iperf,代码行数:23,代码来源:iperf_error.c

示例8: 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;
}
开发者ID:gwtony,项目名称:wsocket,代码行数:22,代码来源:socket_end.c

示例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;
}
开发者ID:gfriloux,项目名称:maelstrom,代码行数:39,代码来源:azy_content_json.c

示例10: while

int CRedWoodDataParse::AddSensorDataToJson(cJSON* sensorJson, cJSON* descJson)
{
    if (sensorJson == NULL)
        return -1;

    cJSON* jsonSon        = NULL;
    cJSON* jsonGrandChild = NULL;
    jsonSon = sensorJson->child;

    while (jsonSon) {
        jsonGrandChild = jsonSon->child;

        if (jsonGrandChild) {
            //get grandchild value
            switch (jsonGrandChild->type) {
            case cJSON_Number:
                cJSON_AddNumberToObject(descJson, 
                    jsonSon->string, jsonGrandChild->valuedouble);
                break;

            case cJSON_String:
                cJSON_AddStringToObject(descJson, 
                    jsonSon->string, jsonGrandChild->valuestring);
                break;

            default:
                break;
            }
        }
        else {
            cJSON_AddNullToObject(descJson, jsonSon->string);
        }

        jsonSon = jsonSon->next;
    }

    return 0;
}
开发者ID:qzluo,项目名称:nbrwapp,代码行数:38,代码来源:redWoodDataParse.cpp

示例11: bubble_caller_print_header

// Print JSON header to gzout
static void bubble_caller_print_header(gzFile gzout, const char* out_path,
                                       BubbleCallingPrefs prefs,
                                       cJSON **hdrs, size_t nhdrs,
                                       const dBGraph *db_graph)
{
  size_t i;

  // Construct cJSON
  cJSON *json = cJSON_CreateObject();

  cJSON_AddStringToObject(json, "file_format", "CtxBubbles");
  cJSON_AddNumberToObject(json, "format_version", BUBBLE_FORMAT_VERSION);

  // Add standard cortex headers
  json_hdr_make_std(json, out_path, hdrs, nhdrs, db_graph);

  // Add parameters used in bubble calling to the header
  json_hdr_augment_cmd(json, "bubbles", "max_flank_kmers",  cJSON_CreateInt(prefs.max_flank_len));
  json_hdr_augment_cmd(json, "bubbles", "max_allele_kmers", cJSON_CreateInt(prefs.max_allele_len));
  cJSON *haploids = cJSON_CreateArray();
  for(i = 0; i < prefs.num_haploid; i++)
    cJSON_AddItemToArray(haploids, cJSON_CreateInt(prefs.haploid_cols[i]));
  json_hdr_augment_cmd(json, "bubbles", "haploid_colours", haploids);

  // Write header to file
  json_hdr_gzprint(json, gzout);

  // Print comments about the format
  gzputs(gzout, "\n");
  gzputs(gzout, "# This file was generated with McCortex\n");
  gzputs(gzout, "#   written by Isaac Turner <[email protected]>\n");
  gzputs(gzout, "#   url: "CORTEX_URL"\n");
  gzputs(gzout, "# \n");
  gzputs(gzout, "# Comment lines begin with a # and are ignored, but must come after the header\n");
  gzputs(gzout, "\n");

  cJSON_Delete(json);
}
开发者ID:ambarrio,项目名称:mccortex,代码行数:39,代码来源:bubble_caller.c

示例12: _set_cjson_field

static void _set_cjson_field(E_KRType type, char *name, U_KRValue *value, cJSON *json) 
{ 
    switch(type) 
    { 
        case KR_TYPE_INT: 
            cJSON_AddNumberToObject(json, name, value->i);
            break;
        case KR_TYPE_LONG: 
            cJSON_AddNumberToObject(json, name, value->l);
            break;
        case KR_TYPE_DOUBLE: 
            cJSON_AddNumberToObject(json, name, value->d);
            break;
        case KR_TYPE_POINTER:
            cJSON_AddNumberToObject(json, name, (long )(value->p));
            break;
        case KR_TYPE_STRING: 
            cJSON_AddStringToObject(json, name, value->s?value->s:" ");
            break;
        default: 
            return; 
    } 
} 
开发者ID:liexusong,项目名称:krproject,代码行数:23,代码来源:kr_engine_context.c

示例13: four_moveGreedy

void four_moveGreedy(char* charOut) {
	{
		cJSON* objectOut = cJSON_CreateObject();
		cJSON* objectIn = NULL;
		
		{
			cJSON_AddStringToObject(objectOut, "strFunction", "four_moveGreedy");
		}
		
		{
			zeromq_send(objectOut);
			
			objectIn = zeromq_recv();
		}
		
		{
			strcpy(charOut, cJSON_GetObjectItem(objectIn, "strOut")->valuestring);
		}
		
		cJSON_Delete(objectOut);
		cJSON_Delete(objectIn);
	}
}
开发者ID:CodeRect,项目名称:teaching-connectfour,代码行数:23,代码来源:four.c

示例14: Parser_PackScrrenshotError

int Parser_PackScrrenshotError(char * errorStr, char **outputStr)
{
	char * out = NULL;
	int outLen = 0;
	cJSON *pSUSICommDataItem = NULL;
	if(errorStr == NULL || outputStr == NULL) return outLen;

	pSUSICommDataItem = cJSON_CreateObject();
	if(pSUSICommDataItem)
	{
		cJSON_AddStringToObject(pSUSICommDataItem, SCREENSHOT_ERROR_REP, errorStr);
	}

	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;
}
开发者ID:ADVANTECH-Corp,项目名称:WISEAgent,代码行数:23,代码来源:Parser.c

示例15: BuildActionJSON

OCStackResult BuildActionJSON(OCAction* action, unsigned char* bufferPtr, uint16_t *remaining)
{
    OCStackResult ret = OC_STACK_ERROR;
    cJSON *json;
    cJSON *body;

    char *jsonStr;
    uint16_t jsonLen;

    OC_LOG(INFO, TAG, PCF("Entering BuildActionJSON"));
    json = cJSON_CreateObject();

    cJSON_AddItemToObject(json, "rep", body = cJSON_CreateObject());

    OCCapability* pointerCapa = action->head;
    while (pointerCapa)
    {
        cJSON_AddStringToObject(body, pointerCapa->capability, pointerCapa->status);
        pointerCapa = pointerCapa->next;
    }

    jsonStr = cJSON_PrintUnformatted(json);

    jsonLen = strlen(jsonStr);
    if (jsonLen < *remaining)
    {
        strcat((char*) bufferPtr, jsonStr);
        *remaining -= jsonLen;
        bufferPtr += jsonLen;
        ret = OC_STACK_OK;
    }

    cJSON_Delete(json);
    free(jsonStr);

    return ret;
}
开发者ID:prajoshpremdas,项目名称:iotivity,代码行数:37,代码来源:oicgroup.c


注:本文中的cJSON_AddStringToObject函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。