本文整理汇总了C++中cJSON_PrintUnformatted函数的典型用法代码示例。如果您正苦于以下问题:C++ cJSON_PrintUnformatted函数的具体用法?C++ cJSON_PrintUnformatted怎么用?C++ cJSON_PrintUnformatted使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cJSON_PrintUnformatted函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: Parser_string
int Parser_string(char *pCommData, char **outputStr, int repCommandID)
{
char * out = NULL;
int outLen = 0;
cJSON *pSUSICommDataItem = NULL;
if(pCommData == NULL || outputStr == NULL) return outLen;
pSUSICommDataItem = cJSON_CreateObject();
switch(repCommandID)
{
case swm_set_mon_objs_rep:
{
cJSON_AddStringToObject(pSUSICommDataItem, SWM_SET_MON_OBJS_REP, pCommData);
break;
}
case swm_error_rep:
{
cJSON_AddStringToObject(pSUSICommDataItem, SWM_ERROR_REP, pCommData);
break;
}
//case swm_kill_prc_rep:
// {
// break;
// }
//case swm_restart_prc_rep:
//case swm_del_all_mon_objs_rep:
//case swm_set_pmi_auto_upload_rep:
//case swm_set_pmi_reqp_req:
default:
{
cJSON_AddStringToObject(pSUSICommDataItem, SWM_SET_MON_OBJS_REP, pCommData);
break;
}
}
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,代码行数:45,代码来源:Parser.c
示例2: cJSON_CreateObject
void Client::createTurnRoom(std::string name, std::string owner, int max, std::map<std::string,std::string> properties, int time)
{
if((_state != ConnectionState::connected) || (_socket == NULL)){
if(_zonelistener != NULL)
{
room _room;
_room.result = ResultCode::connection_error;
_zonelistener->onCreateRoomDone(_room);
}
return;
}
std::map<std::string,std::string>::iterator it;
cJSON *propJSON;
propJSON = cJSON_CreateObject();
for(it = properties.begin(); it != properties.end(); ++it)
{
cJSON_AddStringToObject(propJSON, it->first.c_str(),it->second.c_str());
}
char *cRet = cJSON_PrintUnformatted(propJSON);
std::string prop = cRet;
if(prop.length() >= MAX_PROPERTY_SIZE_BYTES)
{
room _room;
_room.result = ResultCode::size_error;
if(_zonelistener != NULL)
_zonelistener->onCreateRoomDone(_room);
}
int byteLen;
byte *roomReq = buildCreateRoomRequest(name,owner,max, prop, time, byteLen);
char *data = new char[byteLen];
for(int i=0; i< byteLen; ++i)
{
data[i] = roomReq[i];
}
_socket->sockSend(data, byteLen);
delete[] data;
delete[] roomReq;
cJSON_Delete(propJSON);
free(cRet);
}
开发者ID:RajeevRShephertz,项目名称:Ninja_Fight_MultiplayerDemo_Cocos2dX_V3.1,代码行数:45,代码来源:appwarp.cpp
示例3: readfunction
size_t readfunction( void *ptr, size_t size, size_t nmemb, void *userdata)
{
int length = -1;
char * cipher=NULL, content[CONTENT_LEN]={0};
char *out=NULL;
char EpochTime[16]={0};
cJSON *root=NULL;
struct NodeStatus * ns = (struct NodeStatus *)userdata;
if(transfered) return 0;
root=cJSON_CreateObject();
sprintf(EpochTime,"%lx",ns->EpochTime);
cJSON_AddStringToObject(root,"EpochTime",EpochTime);
cJSON_AddStringToObject(root,"NodeName",ns->NodeName);
if(svrversion) {
cJSON_AddStringToObject(root,"Version",ns->Version);
}
if(svrtype) {
cJSON_AddNumberToObject(root,"SvrType",ns->SvrType);
}
strcpy(content, out=cJSON_PrintUnformatted(root));
cJSON_Delete(root);
free(out);
log4c_cdn(mycat, info, "POST", "%s",content);
length = ContentEncode(NODE_3DES_KEY, NODE_3DES_IV, content, &cipher, strlen(content));
if(length<0){
log4c_cdn(mycat, error, "ENDEC", "ContentEncode() failed");
}
if(length<0) exit(1);
memcpy(ptr,cipher,length);
free(cipher);
transfered=1;
return length;
}
开发者ID:frankzzcn,项目名称:msgmgt,代码行数:45,代码来源:InitNodeStatus.c
示例4: cJSON_CreateArray
string App42Service::getJsonStringFromApp42ACLList(vector<App42ACL> &App42ACLObjectArray)
{
cJSON *jsonArray = cJSON_CreateArray();
for (vector<App42ACL>::iterator it = App42ACLObjectArray.begin(); it!= App42ACLObjectArray.end(); it++)
{
cJSON *jsonObject = cJSON_CreateObject();
cJSON_AddStringToObject(jsonObject, it->getUserName().c_str(), it->getPermission().c_str());
cJSON_AddItemToArray(jsonArray, jsonObject);
//cJSON_Delete(jsonObject);
}
char *cptrFormatted = cJSON_PrintUnformatted(jsonArray);
string jsonString = cptrFormatted;
free(cptrFormatted);
cJSON_Delete(jsonArray);
return jsonString;
}
开发者ID:shephertz,项目名称:App42_CloudAPI_RaspberryPi_Sample,代码行数:18,代码来源:App42Service.cpp
示例5: main
int main(void) {
const char *expected = "{\"foo\":\"bar\"}";
char *str;
int retcode = EXIT_SUCCESS;
cJSON *obj;
obj = cJSON_CreateObject();
cJSON_AddStringToObject(obj, "foo", "bar");
str = cJSON_PrintUnformatted(obj);
if (strcmp(str, expected) != 0) {
fprintf(stderr, "Expected %s got %s\n", expected, str);
retcode = EXIT_FAILURE;
}
cJSON_Delete(obj);
cJSON_Free(str);
return retcode;
}
开发者ID:jimwwalker,项目名称:platform,代码行数:18,代码来源:cjson_test.c
示例6: callback
int callback(void *response, int argc, char **argv,char **azColName)
{
cJSON *root,*fmt;
int i;
root=cJSON_CreateObject();
cJSON_AddItemToObject(root, "car",fmt=cJSON_CreateObject());
for (i = 0; i < argc; i++)
{
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
cJSON_AddStringToObject(fmt,azColName[i],argv[i]);
}
strcpy((char *)response,cJSON_PrintUnformatted(root));
//printf("%s",cJSON_PrintUnformatted(root));
cJSON_Delete(root);
return 0;
}
开发者ID:jimlin95,项目名称:webservice_restful,代码行数:18,代码来源:main.c
示例7: cJSON_DeleteItemFromObject
void App42Response::buildJsonDocument(cJSON *json, JSONDocument *jsonDocumnet)
{
cJSON *docIdJson = Util::getJSONChild("_id", json);
if (docIdJson!=NULL)
{
jsonDocumnet->setDocId(Util::getJSONString("$oid", docIdJson));
cJSON_DeleteItemFromObject(json, "_id");
}
cJSON *ownerJson = Util::getJSONChild("_$owner", json);
if (ownerJson!=NULL)
{
jsonDocumnet->setOwner(Util::getJSONString("owner", ownerJson));
cJSON_DeleteItemFromObject(json,"_$owner");
}
string createdAt = Util::getJSONString("_$createdAt", json);
if (createdAt.c_str()!=NULL)
{
jsonDocumnet->setCreatedAt(createdAt);
cJSON_DeleteItemFromObject(json, "_$createdAt");
}
string updatedAt = Util::getJSONString("_$updatedAt", json);
if (updatedAt.c_str()!=NULL)
{
jsonDocumnet->setUpdatedAt(updatedAt);
cJSON_DeleteItemFromObject(json, "_$updatedAt");
}
string event = Util::getJSONString("_$event", json);
if (event.c_str()!=NULL)
{
jsonDocumnet->setEvent(event);
cJSON_DeleteItemFromObject(json, "_$event");
}
char *doc = cJSON_PrintUnformatted(json);
jsonDocumnet->setJsonDoc(doc);
free(doc);
}
开发者ID:RajeevRShephertz,项目名称:App42MarmaladeSample,代码行数:44,代码来源:App42Response.cpp
示例8: cJSON_CreateArray
void WebInterface::generateScreenJson()
{
cJSON* jScreens = cJSON_CreateArray();
for (int nScreen=0;nScreen<_screenManager->getScreenCount();nScreen++)
{
// set current screen
_screenManager->setCurrentScreen(nScreen);
// create screen object and add it
cJSON* jScreen = cJSON_CreateObject();
cJSON_AddItemToArray(jScreens,jScreen);
cJSON_AddStringToObject(jScreen,"name",_screenManager->getCurrentScreenName().getCharPointer());
// create pages object and add it to screen
cJSON* jPages = cJSON_CreateArray();
cJSON_AddItemToObject(jScreen,"pages",jPages);
for (int nPage=0;nPage<_screenManager->getPageCount();nPage++)
{
// set current page
_screenManager->setCurrentPage(nPage);
// create the page object and add it to pages
cJSON* jPage = cJSON_CreateArray();
cJSON_AddItemToObject(jPages,"pages",jPage);
for (int nControl=0;nControl<_screenManager->getControlCount();nControl++)
{
// create the control object and add it to page
cJSON* jControl = cJSON_CreateObject();
cJSON_AddStringToObject(jControl,"name",GrooveControl_getNameString(_screenManager->getControl(nControl)));
cJSON_AddNumberToObject(jControl,"id",_screenManager->getControl(nControl));
cJSON_AddItemToArray(jPage,jControl);
}
}
}
_screenManager->setCurrentScreen(0);
_screenJson = cJSON_PrintUnformatted(jScreens);
cJSON_Delete(jScreens);
}
开发者ID:eriser,项目名称:rejuce,代码行数:44,代码来源:WebInterface.cpp
示例9: construct_msg
/***************************************************************************
Function: construct_msg
Description: construct IPC message
Input: msgtype
text_str
Output: pmsg
Return: negative:error
positive:the length of message data, including null
Others: none
***************************************************************************/
static int construct_msg(clientAdminMsgType msgtype, const char *text_str, struct client_admin_msgbuf *pmsg)
{
int re;
char *out;
cJSON *msg_json;
if ( (msgtype < clientAdmintMsgPassword) || (msgtype > clientAdmintMsgAlias) ) {
CA_DEBUG("msgtype error %d\n", msgtype);
return -1;
}
if (text_str == NULL) {
CA_DEBUG("text_str NULL\n");
return -1;
}
pmsg->mtype = msgtype;
msg_json = cJSON_CreateObject();
if (!msg_json) {
CA_DEBUG("Create msg_json failed\n");
return -2;
}
switch (msgtype) {
case clientAdmintMsgPassword:
cJSON_AddStringToObject(msg_json, "password", text_str);
break;
case clientAdmintMsgAlias:
cJSON_AddStringToObject(msg_json, "alias", text_str);
break;
default: // already check, just fo completed
cJSON_Delete(msg_json);
CA_DEBUG("msgtype error %d\n", msgtype);
return -2;
}
out = cJSON_PrintUnformatted(msg_json);
cJSON_Delete(msg_json);
if (!out) {
CA_DEBUG("cJSON_PrintUnformatted msg_json failed\n");
return -3;
}
re = snprintf(pmsg->mtext, CLIENTADMIN_MSG_LEN, "%s", out);
free(out);
return (re+1); //including null
}
开发者ID:yanlunyao,项目名称:gateway,代码行数:54,代码来源:clientAdmin.c
示例10: generateInsertMessageWithQueryType
ssap_message* generateInsertMessageWithQueryType(const char* sessionKey, const char* ontology, const char* data, SSAPQueryType queryType){
ssap_message* insertMessage = allocateSsapMessage();
cJSON *body;
body=cJSON_CreateObject();
switch(queryType){
case NATIVE:
cJSON_AddItemToObject(body, "queryType", cJSON_CreateString("NATIVE"));
cJSON_AddItemToObject(body, "query", cJSON_CreateNull());
cJSON_AddItemToObject(body, "data", cJSON_CreateString(data));
break;
case SQLLIKE:
cJSON_AddItemToObject(body, "queryType", cJSON_CreateString("SQLLIKE"));
cJSON_AddItemToObject(body, "query", cJSON_CreateString(data));
cJSON_AddItemToObject(body, "data", cJSON_CreateNull());
break;
case BDH:
cJSON_AddItemToObject(body, "queryType", cJSON_CreateString("BDH"));
cJSON_AddItemToObject(body, "query", cJSON_CreateString(data));
cJSON_AddItemToObject(body, "data", cJSON_CreateNull());
break;
default:
cJSON_AddItemToObject(body, "queryType", cJSON_CreateNull());
cJSON_AddItemToObject(body, "query", cJSON_CreateNull());
cJSON_AddItemToObject(body, "data", cJSON_CreateString(data));
break;
}
insertMessage->body=cJSON_PrintUnformatted(body);
insertMessage->direction = REQUEST;
insertMessage->messageId = NULL;
insertMessage->messageType=INSERT;
insertMessage->ontology=(char*) malloc((strlen(ontology)+1)*sizeof(char));
strcpy(insertMessage->ontology, ontology);
insertMessage->sessionKey=(char*) malloc((strlen(sessionKey)+1)*sizeof(char));
strcpy(insertMessage->sessionKey, sessionKey);
insertMessage->persistenceType=MONGODB;
cJSON_Delete(body);
return insertMessage;
}
开发者ID:Sofia2,项目名称:c-api,代码行数:43,代码来源:SsapMessageGenerator.c
示例11: BuildStorageBody
string BuildStorageBody(string json)
{
cJSON *bodyJSON = cJSON_CreateObject();
cJSON *app42JSON = cJSON_CreateObject();
cJSON *storageJSON = cJSON_CreateObject();
cJSON_AddStringToObject(storageJSON, "jsonDoc", json.c_str());
cJSON_AddItemReferenceToObject(app42JSON, "storage", storageJSON);
cJSON_AddItemReferenceToObject(bodyJSON, "app42", app42JSON);
char *cptrFormatted = cJSON_PrintUnformatted(bodyJSON);
string bodyString = cptrFormatted;
cJSON_Delete(storageJSON);
cJSON_Delete(app42JSON);
cJSON_Delete(bodyJSON);
free(cptrFormatted);
return bodyString;
}
开发者ID:asmodehn,项目名称:App42_Cocos2DX_SDK,代码行数:19,代码来源:StorageService.cpp
示例12: cJSON_CreateObject
void Client::sendPrivateChat(std::string toUser, std::string message)
{
if((_state != ConnectionState::connected) || (_socket == NULL)){
if(_chatlistener != NULL)
{
_chatlistener->onSendPrivateChatDone(ResultCode::connection_error);
}
return;
}
if(message.length() >= 512)
{
if(_chatlistener != NULL)
_chatlistener->onSendPrivateChatDone(ResultCode::bad_request);
return;
}
std::string payload;
int len;
cJSON *payloadJSON;
payloadJSON = cJSON_CreateObject();
cJSON_AddStringToObject(payloadJSON, "to" ,toUser.c_str());
cJSON_AddStringToObject(payloadJSON, "chat" ,message.c_str());
char *cRet = cJSON_PrintUnformatted(payloadJSON);
payload = cRet;
byte * req = buildWarpRequest(RequestType::private_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:Liangzhijin08,项目名称:AppWarpCocos2DX,代码行数:42,代码来源:appwarp.cpp
示例13: generateJoinMessage
ssap_message* generateJoinMessage(const char* token, const char* instance){
ssap_message* joinMessage = allocateSsapMessage();
cJSON *body;
body=cJSON_CreateObject();
cJSON_AddItemToObject(body, "token", cJSON_CreateString(token));
cJSON_AddItemToObject(body, "instance", cJSON_CreateString(instance));
joinMessage->body=cJSON_PrintUnformatted(body);
joinMessage->direction = REQUEST;
joinMessage->messageId=NULL;
joinMessage->messageType=JOIN;
joinMessage->ontology=NULL;
joinMessage->sessionKey=NULL;
joinMessage->persistenceType=MONGODB;
cJSON_Delete(body);
return joinMessage;
}
开发者ID:Sofia2,项目名称:c-api,代码行数:20,代码来源:SsapMessageGenerator.c
示例14: cJSON_CreateArray
// 将URL队列 序列化为 json 文本
char * communication::encoding (queue<url *> & urlQueue)
{
cJSON * root ;
root = cJSON_CreateArray();
while(!urlQueue.empty())
{
url * u = urlQueue.front();
cJSON * item = cJSON_CreateObject();
cJSON_AddStringToObject(item,"HOST",u->getHost());
cJSON_AddStringToObject(item,"FILE",u->getFile());
cJSON_AddNumberToObject(item,"PORT",u->getPort());
cJSON_AddNumberToObject(item,"PRIORITY",u->getPriority());
cJSON_AddNumberToObject(item,"DEPTH",u->getDepth());
cJSON_AddItemToArray(root ,item);
urlQueue.pop();
}
char * out = cJSON_PrintUnformatted(root);
cJSON_Delete(root);
return out;
}
开发者ID:LixinZhang,项目名称:DistributedCrawler,代码行数:21,代码来源:communication.cpp
示例15: cJSON_CreateArray
string AlprImpl::toJson(const vector< AlprResult > results)
{
cJSON *root = cJSON_CreateArray();
for (int i = 0; i < results.size(); i++)
{
cJSON *resultObj = createJsonObj( &results[i] );
cJSON_AddItemToArray(root, resultObj);
}
// Print the JSON object to a string and return
char *out;
out=cJSON_PrintUnformatted(root);
cJSON_Delete(root);
string response(out);
free(out);
return response;
}
开发者ID:jesperhag,项目名称:openalpr,代码行数:20,代码来源:alpr_impl.cpp
示例16: ont_video_dev_set_channels
int ont_video_dev_set_channels(void *_dev, int channels)
{
ont_device_t *dev = _dev;
char dsname[32];
int i = 0;
cJSON *json = cJSON_CreateNull();
cJSON_AddItemToObject(json, "null", cJSON_CreateString("null"));
char *jsonValue = cJSON_PrintUnformatted(json);
for (i = 0; i < channels; i++)
{
ont_platform_snprintf(dsname, sizeof(dsname), "ont_video_%d_mqtttestvideo", i + 1);
ont_device_add_dp_object(dev, dsname, jsonValue);
}
ont_device_send_dp(dev);
ont_platform_free(jsonValue);
cJSON_Delete(json);
return 0;
}
开发者ID:taolinbg,项目名称:video_sdk,代码行数:20,代码来源:ont_mqtt_video.c
示例17: cJSON_AddNumberToObject
/***************************************************************************
Function: package_json_callback
Description: 发到5017端口的callback数据格式
Input:
Output: 输出封装好的callback数据的地址
Return:
Others:
****************************************************************************/
char *package_json_callback(int type,char *pic_name)
{
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 );
if(type == 0)
{
cJSON_AddStringToObject(root,"ipaddr",pic_name);
}
out=cJSON_PrintUnformatted(root);
cJSON_Delete(root);
return out;
}
开发者ID:Jeansfirm,项目名称:glexer-ipc,代码行数:29,代码来源:IPCCapture_bak_file.c
示例18: make_poll_post_data
static void make_poll_post_data(str_t* post_data)
{
cJSON* cjson_poll_post = cJSON_CreateObject();
str_t tmp = empty_str;
cJSON_AddStringToObject(cjson_poll_post, "clientid", CLIENTID);
cJSON_AddStringToObject(cjson_poll_post, "psessionid", robot.session.ptr);
cJSON_AddNumberToObject(cjson_poll_post, "key", 0);
cJSON_AddItemToObject(cjson_poll_post, "ids", cJSON_CreateArray());
post_data->ptr = cJSON_PrintUnformatted(cjson_poll_post);
post_data->len = strlen(post_data->ptr);
cJSON_Delete(cjson_poll_post);
str_cpy(&tmp, str_from("r="));
str_ncat(&tmp, post_data->ptr, post_data->len);
str_cat(&tmp, "&clientid="CLIENTID"&psessionid=");
str_ncat(&tmp, robot.session.ptr, robot.session.len);
str_free(*post_data);
urlencode(tmp, post_data);
str_free(tmp);
}
开发者ID:lwch,项目名称:QQRobot,代码行数:20,代码来源:core_module.c
示例19: cJSON_DeleteItemFromObject
char *rm_item(char *old,char *id)
{
cJSON *root;
char *out;
if(old!=NULL)
root=cJSON_Parse(old);
else
root=cJSON_CreateObject();
cJSON *data;
data=cJSON_GetObjectItem(root,id);
if(data)
{
cJSON_DeleteItemFromObject(root, id);
}
out=cJSON_PrintUnformatted(root);
cJSON_Delete(root);
if(old)
free(old);
return out;
}
开发者ID:blueskycoco,项目名称:zhao,代码行数:20,代码来源:netlib.c
示例20: generateUpdateMessageWithQueryType
ssap_message* generateUpdateMessageWithQueryType(const char* sessionKey, const char* ontology, const char* query, SSAPQueryType queryType){
ssap_message* updateMessage = allocateSsapMessage();
cJSON *body;
//Crea la raiz del JSON
body=cJSON_CreateObject();
//Añade las propiedades al body
cJSON_AddItemToObject(body, "data", cJSON_CreateNull());
cJSON_AddItemToObject(body, "query", cJSON_CreateString(query));
switch(queryType){
case NATIVE:
cJSON_AddItemToObject(body, "queryType", cJSON_CreateString("NATIVE"));
break;
case SQLLIKE:
cJSON_AddItemToObject(body, "queryType", cJSON_CreateString("SQLLIKE"));
break;
case BDH:
cJSON_AddItemToObject(body, "queryType", cJSON_CreateString("BDH"));
break;
default:
cJSON_AddItemToObject(body, "queryType", cJSON_CreateNull());
break;
}
updateMessage->body=cJSON_PrintUnformatted(body);
updateMessage->direction = REQUEST;
updateMessage->messageId = NULL;
updateMessage->messageType=UPDATE;
updateMessage->ontology=(char*) malloc((strlen(ontology)+1)*sizeof(char));
strcpy(updateMessage->ontology, ontology);
updateMessage->sessionKey=(char*) malloc((strlen(sessionKey)+1)*sizeof(char));
strcpy(updateMessage->sessionKey, sessionKey);
updateMessage->persistenceType=MONGODB;
cJSON_Delete(body);
return updateMessage;
}
开发者ID:Sofia2,项目名称:c-api,代码行数:41,代码来源:SsapMessageGenerator.c
注:本文中的cJSON_PrintUnformatted函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论