本文整理汇总了C++中cJSON_Delete函数的典型用法代码示例。如果您正苦于以下问题:C++ cJSON_Delete函数的具体用法?C++ cJSON_Delete怎么用?C++ cJSON_Delete使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cJSON_Delete函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cJSON_CreateObject
/* Convert Eventinfo to json */
char *Eventinfo_to_jsonstr(Eventinfo *lf)
{
cJSON *root;
cJSON *rule;
cJSON *file_diff;
char *out;
root = cJSON_CreateObject();
cJSON_AddItemToObject(root, "rule", rule = cJSON_CreateObject());
cJSON_AddNumberToObject(rule, "level", lf->generated_rule->level);
if (lf->generated_rule->comment) {
cJSON_AddStringToObject(rule, "comment", lf->generated_rule->comment);
}
if (lf->generated_rule->sigid) {
cJSON_AddNumberToObject(rule, "sidid", lf->generated_rule->sigid);
}
if (lf->generated_rule->cve) {
cJSON_AddStringToObject(rule, "cve", lf->generated_rule->cve);
}
if (lf->generated_rule->cve) {
cJSON_AddStringToObject(rule, "info", lf->generated_rule->info);
}
if (lf->action) {
cJSON_AddStringToObject(root, "action", lf->action);
}
if (lf->srcip) {
cJSON_AddStringToObject(root, "srcip", lf->srcip);
}
if (lf->srcport) {
cJSON_AddStringToObject(root, "srcport", lf->srcport);
}
if (lf->srcuser) {
cJSON_AddStringToObject(root, "srcuser", lf->srcuser);
}
if (lf->dstip) {
cJSON_AddStringToObject(root, "dstip", lf->dstip);
}
if (lf->dstport) {
cJSON_AddStringToObject(root, "dstport", lf->dstport);
}
if (lf->dstuser) {
cJSON_AddStringToObject(root, "dstuser", lf->dstuser);
}
if (lf->location) {
cJSON_AddStringToObject(root, "location", lf->location);
}
if (lf->full_log) {
cJSON_AddStringToObject(root, "full_log", lf->full_log);
}
if (lf->filename) {
cJSON_AddItemToObject(root, "file", file_diff = cJSON_CreateObject());
cJSON_AddStringToObject(file_diff, "path", lf->filename);
if (lf->md5_before && lf->md5_after && strcmp(lf->md5_before, lf->md5_after) != 0 ) {
cJSON_AddStringToObject(file_diff, "md5_before", lf->md5_before);
cJSON_AddStringToObject(file_diff, "md5_after", lf->md5_after);
}
if (lf->sha1_before && lf->sha1_after && !strcmp(lf->sha1_before, lf->sha1_after) != 0) {
cJSON_AddStringToObject(file_diff, "sha1_before", lf->sha1_before);
cJSON_AddStringToObject(file_diff, "sha1_after", lf->sha1_after);
}
if (lf->owner_before && lf->owner_after && !strcmp(lf->owner_before, lf->owner_after) != 0) {
cJSON_AddStringToObject(file_diff, "owner_before", lf->owner_before);
cJSON_AddStringToObject(file_diff, "owner_after", lf->owner_after);
}
if (lf->gowner_before && lf->gowner_after && !strcmp(lf->gowner_before, lf->gowner_after) != 0 ) {
cJSON_AddStringToObject(file_diff, "gowner_before", lf->gowner_before);
cJSON_AddStringToObject(file_diff, "gowner_after", lf->gowner_after);
}
if (lf->perm_before && lf->perm_after && lf->perm_before != lf->perm_after) {
cJSON_AddNumberToObject(file_diff, "perm_before", lf->perm_before);
cJSON_AddNumberToObject(file_diff, "perm_after", lf->perm_after);
}
}
out = cJSON_PrintUnformatted(root);
cJSON_Delete(root);
return out;
}
示例2: printf
bool VGW_Vod_Stream::StartOneStream(int iStreamID,char *strUrl,char *strRegionid,char* strUserID,char *vodname,char *posterurl,int fd)
{
if(fd)
{
MapVodPlay::iterator fdfind= m_mapVod_player.find(iStreamID);
if(fdfind != m_mapVod_player.end())
{
//找到对应信息
Stream* sptmpRequest = fdfind->second;
if(fd != sptmpRequest->m_clientSocket)
{
printf("the socket is changed,before = %d,after = %d\n",sptmpRequest->m_clientSocket,fd);
fflush(stdout);
sptmpRequest->m_clientSocket = fd;
}
}
}
if(!Connect_VODServer())
{
m_mapVod_player.clear();
printf("error can't connect to server \n");
fflush(stdout);
return false;
}
if(pRet_root)
{
cJSON_Delete(pRet_root);
pRet_root = NULL;
}
char strSeesionId[32]={0};
sprintf(strSeesionId,"%d",iStreamID);
char strSID[32]="3002";
char strstype[32]="3302";
char strctype[32]="5";
char strvtype[32]="2";
char strareaid[32]="2";
char strMsg[1024]={0};
char striip[32]="3301";
char striport[32]="3301";
char strsip[32]={0};
strcpy(strsip,strMyServerIP);
char strsport[32]={0};
sprintf(strsport,"%d",iMSIServerPort);
char strRegionID[32]="0x0603"; //"0x0604"
// char strOutUrl[512]= "rtsp://192.168.100.11:8845/yjy_ipqam/bjtv.ts"; //"rtsp://192.168.100.11:8845/yjy_ipqam/8081/gyc.ts";
// unsigned long ilen= sizeof(strOutUrl);
unsigned long ulInLen=strlen(strUrl);
ZBase64 tmpEncode;
std::string strencodemsg = tmpEncode.Encode((unsigned char*)strUrl,ulInLen);
sprintf(strMsg,"%s|%s",strencodemsg.c_str(),strRegionid);
printf("---%s \n",strUrl);
fflush(stdout);
printf("%s \n",strMsg);
fflush(stdout);
//需要得到返回值才可作为点播成功
pRet_root = cJSON_CreateObject();
/* Requst_Json_str(2,"appuserid",strappuserid);
Requst_Json_str(2,"spuserid",strspuserid);
Requst_Json_str(2,"areaid",strareaid);
Requst_Json_str(2,"sid",strSID);
Requst_Json_str(2,"iip",striip);
Requst_Json_str(2,"iport",striport);
Requst_Json_str(2,"sip",strsip);
Requst_Json_str(2,"sport",strsport);
Requst_Json_str(2,"msg",strMsg);
*/
Requst_Json_str(2,"cmd","login");
Requst_Json_str(2,"sessionid",strSeesionId);
Requst_Json_str(2,"sid",strSID);
Requst_Json_str(2,"stype",strstype);
Requst_Json_str(2,"ctype",strctype);
Requst_Json_str(2,"vtype",strctype);
Requst_Json_str(2,"url","");
Requst_Json_str(2,"areaid",strareaid);
Requst_Json_str(2,"sip",strsip);
Requst_Json_str(2,"sport",strsport);
Requst_Json_str(2,"serialno",strSeesionId);
Requst_Json_str(2,"msg",strMsg);
Requst_Json_str(2,"vodname",vodname);
Requst_Json_str(2,"posterurl",posterurl);
Requst_Json_str(2,"appuserid",strSeesionId);
Requst_Json_str(2,"spuserid",strUserID);
Send_Jsoon_str();
return true;
}
示例3: cJSON_DeleteItemFromArray
void cJSON_DeleteItemFromArray(cJSON *array,int which) {cJSON_Delete(cJSON_DetachItemFromArray(array,which));}
示例4: platform_anzhi_auth
int platform_anzhi_auth(const char *param, auth_cb cb, void *args)
{
LOG_DEBUG("net", "platform_anzhi_auth: %p", args);
cJSON *json = cJSON_Parse(param);
if (json == NULL) {
return PLATFORM_PARAM_ERROR;
}
cJSON *setting = platform_get_json(PLAT_ANZHI);
if (setting == NULL) {
return PLATFORM_SETTING_ERROR;
}
cJSON *url = cJSON_GetObjectItem(setting, "URL");
if (url == NULL) {
return PLATFORM_SETTING_ERROR;
}
cJSON *appKey = cJSON_GetObjectItem(setting, "appKey");
if (appKey == NULL) {
return PLATFORM_SETTING_ERROR;
}
cJSON *appSecret = cJSON_GetObjectItem(setting, "appSecret");
if (appSecret == NULL) {
return PLATFORM_SETTING_ERROR;
}
cJSON *token = cJSON_GetObjectItem(json, "token");
if (token == NULL) {
return PLATFORM_PARAM_ERROR;
}
cJSON *userId = cJSON_GetObjectItem(json, "userId");
if (userId == NULL) {
return PLATFORM_PARAM_ERROR;
}
//appkey+account+sid+appsecret
std::string ctx = appKey->valuestring;
ctx.append(userId->valuestring);
ctx.append(token->valuestring);
ctx.append(appSecret->valuestring);
std::string sign = base64_encode(ctx.c_str(), ctx.size(), false);
struct tm ctm;
time64_t now = time_ms();
char now_s[64];
time_t tm = (time_t)(now / 1000);
localtime_r(&tm, &ctm);
strftime(now_s, sizeof(now_s), "%Y%m%d%H%M%S", &ctm);
sprintf(now_s, "%s%lld", now_s, now - tm * 1000);
std::string post_url;
post_url.append(url->valuestring);
post_url.append("?time=");
post_url.append(now_s);
post_url.append("&appkey=");
post_url.append(appKey->valuestring);
post_url.append("&account=");
post_url.append(userId->valuestring);
post_url.append("&sid=");
post_url.append(token->valuestring);
post_url.append("&sign=");
post_url.append(sign);
cJSON_Delete(json);
// do post request
plat_json_req *json_req = E_NEW plat_json_req(cb, args);
json_req->plat_type = PLAT_ANZHI;
json_req->channel = "anzhi";
json_req->param = std::string(param);
http_json(HTTP_POST, post_url.c_str(), "", write_callback, json_req);
LOG_DEBUG("net", "url: %s", post_url.c_str());
return PLATFORM_OK;
}
示例5: CHPRepPayloadToJson
//.........这里部分代码省略.........
cJSON_AddStringToObject(outJson,val->name,val->str);
break;
case OCREP_PROP_OBJECT:
{
cJSON *objJson = CHPRepPayloadToJson(val->obj);
if (objJson != NULL)
{
cJSON_AddItemToObject(outJson,val->name,objJson);
}
break;
}
case OCREP_PROP_ARRAY:
{
unsigned int i = 0;
int arraySize = (int)val->arr.dimensions[0];
switch (val->arr.type)
{
case OCREP_PROP_INT:
OIC_LOG_V(DEBUG, TAG, "%s(int array)", val->name);
if (arraySize > 0)
{
int castVal[val->arr.dimensions[0]];
for (i = 0 ; i < (unsigned int)arraySize ; i++)
{
castVal[i] = (int)val->arr.iArray[i];
}
cJSON *array = cJSON_CreateIntArray(castVal,arraySize);
if (array != NULL)
{
cJSON_AddItemToObject(outJson,val->name,array);
}
}
break;
case OCREP_PROP_DOUBLE:
OIC_LOG_V(DEBUG, TAG, "%s(double array)", val->name);
if (arraySize > 0)
{
cJSON *array = cJSON_CreateDoubleArray(val->arr.dArray,arraySize);
if (array != NULL)
{
cJSON_AddItemToObject(outJson,val->name,array);
}
}
break;
case OCREP_PROP_STRING:
OIC_LOG_V(DEBUG, TAG, "%s(string array)", val->name);
if (arraySize > 0)
{
cJSON *array = cJSON_CreateStringArray((const char**)val->arr.strArray,
arraySize);
if (array != NULL)
{
cJSON_AddItemToObject(outJson,val->name,array);
}
}
break;
case OCREP_PROP_OBJECT:
if (arraySize > 0)
{
cJSON *arrayJson = cJSON_CreateArray();
for (i = 0 ; i < (unsigned int)arraySize ; i++)
{
cJSON *objJson = CHPRepPayloadToJson(val->arr.objArray[i]);
if (objJson != NULL && arrayJson != NULL)
{
cJSON_AddItemToArray(arrayJson, objJson);
}
}
if (arrayJson != NULL)
{
cJSON_AddItemToObject(outJson,val->name,arrayJson);
}
}
break;
case OCREP_PROP_BOOL:
//TODO : Not support - cJSON_CreateBoolArray
break;
default:
OIC_LOG_V(ERROR, TAG, "Unknown/unsupported array type: %s", val->name);
break;
}
break;
}
default:
OIC_LOG_V(ERROR, TAG, "Unknown type: %s", val->name);
break;
}
val = val->next;
}
if( repData->values != NULL)
{
return outJson;
}
else
{
cJSON_Delete(outJson);
return NULL;
}
}
示例6: create_objects
/* Create a bunch of objects as demonstration. */
void create_objects() {
cJSON *root, *fmt, *img, *thm, *fld;
char *out;
int i; /* declare a few. */
/* Our "days of the week" array: */
const char *strings[7] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
/* Our matrix: */
int numbers[3][3] = {{0, -1, 0},
{1, 0, 0},
{0, 0, 1}};
/* Our "gallery" item: */
int ids[4] = {116, 943, 234, 38793};
/* Our array of "records": */
struct record fields[2] = {
{"zip", 37.7668, -1.223959e+2, "", "SAN FRANCISCO", "CA", "94107", "US"},
{"zip", 37.371991, -1.22026e+2, "", "SUNNYVALE", "CA", "94085", "US"}};
/* Here we construct some JSON standards, from the JSON site. */
/* Our "Video" datatype: */
root = cJSON_CreateObject();
cJSON_AddItemToObject(root, "name", cJSON_CreateString("Jack (\"Bee\") Nimble"));
cJSON_AddItemToObject(root, "format", fmt = cJSON_CreateObject());
cJSON_AddStringToObject(fmt, "type", "rect");
cJSON_AddNumberToObject(fmt, "width", 1920);
cJSON_AddNumberToObject(fmt, "height", 1080);
cJSON_AddFalseToObject (fmt, "interlace");
cJSON_AddNumberToObject(fmt, "frame rate", 24);
out = cJSON_Print(root);
cJSON_Delete(root);
printf("%s\n", out);
free(out); /* Print to text, Delete the cJSON, print it, release the string. */
/* Our "days of the week" array: */
root = cJSON_CreateStringArray(strings, 7);
out = cJSON_Print(root);
cJSON_Delete(root);
printf("%s\n", out);
free(out);
/* Our matrix: */
root = cJSON_CreateArray();
for (i = 0; i < 3; i++) cJSON_AddItemToArray(root, cJSON_CreateIntArray(numbers[i], 3));
/* cJSON_ReplaceItemInArray(root,1,cJSON_CreateString("Replacement")); */
out = cJSON_Print(root);
cJSON_Delete(root);
printf("%s\n", out);
free(out);
/* Our "gallery" item: */
root = cJSON_CreateObject();
cJSON_AddItemToObject(root, "Image", img = cJSON_CreateObject());
cJSON_AddNumberToObject(img, "Width", 800);
cJSON_AddNumberToObject(img, "Height", 600);
cJSON_AddStringToObject(img, "Title", "View from 15th Floor");
cJSON_AddItemToObject(img, "Thumbnail", thm = cJSON_CreateObject());
cJSON_AddStringToObject(thm, "Url", "http:/*www.example.com/image/481989943");
cJSON_AddNumberToObject(thm, "Height", 125);
cJSON_AddStringToObject(thm, "Width", "100");
cJSON_AddItemToObject(img, "IDs", cJSON_CreateIntArray(ids, 4));
out = cJSON_Print(root);
cJSON_Delete(root);
printf("%s\n", out);
free(out);
/* Our array of "records": */
root = cJSON_CreateArray();
for (i = 0; i < 2; i++) {
cJSON_AddItemToArray(root, fld = cJSON_CreateObject());
cJSON_AddStringToObject(fld, "precision", fields[i].precision);
cJSON_AddNumberToObject(fld, "Latitude", fields[i].lat);
cJSON_AddNumberToObject(fld, "Longitude", fields[i].lon);
cJSON_AddStringToObject(fld, "Address", fields[i].address);
cJSON_AddStringToObject(fld, "City", fields[i].city);
cJSON_AddStringToObject(fld, "State", fields[i].state);
cJSON_AddStringToObject(fld, "Zip", fields[i].zip);
cJSON_AddStringToObject(fld, "Country", fields[i].country);
}
/* cJSON_ReplaceItemInObject(cJSON_GetArrayItem(root,1),"City",cJSON_CreateIntArray(ids,4)); */
out = cJSON_Print(root);
cJSON_Delete(root);
printf("%s\n", out);
free(out);
}
示例7: AnalysisInitJson
//.........这里部分代码省略.........
}
item = cJSON_GetObjectItem(root, "TeamCount");
TeamCount = item -> valueint;
if((item = cJSON_GetObjectItem(root, "NeedAnswer")))
{
if(strcasecmp(item -> valuestring, YES) == 0)
{
//需要相应,则给对方发送相应。xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//这里是不是要改成验证CMDID的格式,那么打包的函数就不应该使用CreateMultiplexJson
AgentAnswer = CreateMultiplexJson("AgentAnswer", getCommandID());
}
}
//根据pc的时间,校准本地的时间。
item = cJSON_GetObjectItem(root, "Time");
memset(time, 0 ,sizeof(time));
strncpy(time, item -> valuestring, strlen(item -> valuestring));
year = (time[2] - '0')*10 + (time[3] - '0') + 2000;
month = (time[5] - '0')*10 + (time[6] - '0');
day = (time[8] - '0')*10 + (time[9] - '0');
hour = (time[11] - '0')*10 + (time[12] - '0');
minute = (time[14] - '0')*10 + (time[15] - '0');
second = (time[17] - '0')*10 + (time[18] - '0');
AdjustClockTime();
item = cJSON_GetObjectItem(root, "SupplyAirToAir");
status.Equipment.AirToAir = item -> valueint;
item = cJSON_GetObjectItem(root, "SupplyAirToGround");
status.Equipment.AirToGround = item -> valueint;
item = cJSON_GetObjectItem(root, "SupplyLife");
status.Equipment.SupplyLife = item ->valueint;
pJsonArray = cJSON_GetObjectItem(root, "InitDetails");
if (pJsonArray)
{
int size = cJSON_GetArraySize(pJsonArray);
for(ii = 0; ii < size; ii++)
{
pArrayItem = cJSON_GetArrayItem(pJsonArray, ii);
if (pArrayItem)
{
item2 = cJSON_GetObjectItem(pArrayItem, "AgentID");
if( item2 -> valueint != status.AgentID ) continue;
else{
item2 = cJSON_GetObjectItem(pArrayItem, "GroupAgent");
status.GroupAgent = item2 -> valueint;
item2 = cJSON_GetObjectItem(pArrayItem, "TeamID");
status.TeamID = item2 -> valueint;
item2 = cJSON_GetObjectItem(pArrayItem, "MyTeamCount");
status.MyTeamCount = item2 -> valueint;
item2 = cJSON_GetObjectItem(pArrayItem, "Character");
memset(status.Character, 0 ,sizeof(status.Character));
strncpy(status.Character, item2 -> valuestring, strlen(item2->valuestring));
if((strcasecmp(status.Character,GENERAL) == 0)) status.CharacterID = 12;
if((strcasecmp(status.Character,GROUP) == 0)) status.CharacterID = 11;
if((strcasecmp(status.Character,MAJOR) == 0)) status.CharacterID = 10;
Flags.isBreak = 1;
Flags.isSendRegister = 1;
isWakeup = 1;
sResOutput(">>> Init ownStatus is Okay "," >>>");
break;
}
}
}
}
else{
sResOutput(">>>[Exc]: ","pJsonArray >>>");
}
}
}
sResOutput(">>> "," Init Finished >>>");
cJSON_Delete(root);
root = NULL;
}
示例8: printf
//.........这里部分代码省略.........
ptmpRequest.Requst_Json_str(2,"cmd","change_stream");
char txt[32] ={0};
sprintf(txt,"%d",iRetcode);
ptmpRequest.Requst_Json_str(2,"ret_code",txt);
ptmpRequest.Requst_Json_str(2,"serialno",strSerialNo);
ptmpRequest.Send_Jsoon_str();
}
else if(strcmp(pcmd->valuestring, "check_session") == 0)
{
printf("--check_session exception\n");
//通过
cJSON* psessionid = cJSON_GetObjectItem(pRoot, "sessionid");
char strsessionid[128] ={0};
int iSeessionID = 0;
if(psessionid)
{
memcpy(strsessionid,psessionid->valuestring,strlen(psessionid->valuestring)+1);
iSeessionID = atoi(strsessionid);
}
cJSON* pSerialNo = cJSON_GetObjectItem(pRoot,"serialno");
char strSerialNo[128] ={0};
if(pSerialNo)
memcpy(strSerialNo,pSerialNo->valuestring,strlen(pSerialNo->valuestring)+1);
//cJSON *pRet_root;
ptmpRequest.pRet_root = cJSON_CreateObject();
ptmpRequest.Requst_Json_str(2,"cmd","check_session");
ptmpRequest.Requst_Json_str(2,"sessionid",strsessionid);
ptmpRequest.Requst_Json_str(1,"task_id",strsessionid);
char txt[32] ={0};
sprintf(txt,"%d",iRetcode);
ptmpRequest.Requst_Json_str(2,"ret_code",txt);
ptmpRequest.Requst_Json_str(2,"serialno",strSerialNo);
}
else if(strcmp(pcmd->valuestring, "req_ads_stream") == 0)
{
printf("--req stream_session exception\n");
//通过
cJSON* psessionid = cJSON_GetObjectItem(pRoot, "sessionid");
char strsessionid[128] ={0};
int iSeessionID = 0;
if(psessionid)
{
memcpy(strsessionid,psessionid->valuestring,strlen(psessionid->valuestring)+1);
iSeessionID = atoi(strsessionid);
}
cJSON* pSerialNo = cJSON_GetObjectItem(pRoot,"serialno");
char strSerialNo[128] ={0};
if(pSerialNo)
memcpy(strSerialNo,pSerialNo->valuestring,strlen(pSerialNo->valuestring)+1);
//cJSON *pRet_root;
ptmpRequest.pRet_root = cJSON_CreateObject();
ptmpRequest.Requst_Json_str(2,"cmd","req_ads_stream");
ptmpRequest.Requst_Json_str(2,"sessionid",strsessionid);
char strnoip[128]={0};
strcpy(strnoip,"1.1.1.1");
char strport[32]={0};
strcpy(strport,"1");
ptmpRequest.Requst_Json_str(1,"switch_ip",strnoip);
ptmpRequest.Requst_Json_str(1,"switch_port",strport);
char txt[32] ={0};
sprintf(txt,"%d",iRetcode);
ptmpRequest.Requst_Json_str(2,"ret_code",txt);
ptmpRequest.Requst_Json_str(2,"serialno",strSerialNo);
}
}
}
char cJsonBuff[1024 * 2];
char * m_tmp;
m_tmp = cJSON_Print(ptmpRequest.pRet_root);
memset(cJsonBuff, 0, sizeof(cJsonBuff));
sprintf(cJsonBuff, "%sXXEE", m_tmp);
free(m_tmp);
printf("-----%s \n",cJsonBuff);
fflush(stdout);
cJSON_Delete(ptmpRequest.pRet_root);
//copy to output
strcpy(strOutUrl,cJsonBuff);
return 0;
}
示例9:
cJSON *cJSON_CreateString(const char *string) {cJSON *item=cJSON_New_Item();if(item){item->type=cJSON_String;item->valuestring=cJSON_strdup(string);if(!item->valuestring){cJSON_Delete(item);return 0;}}return item;}
示例10: LoadJSONMesh
void LoadJSONMesh(PP_Resource context,
PPB_OpenGLES2* gl,
const char* mesh,
Transformations* psMatrices,
int* piNumIndices,
int* piNumVertices,
GLuint* puiVBO,
GLuint* puiIBO)
{
uint16_t* pui16Indices;
float* pfVertices;
float* pfTexCoords;
float* pfNormals;
int idx;
int vtx;
int iNumIndices;
int iNumVertices;
float fMinX;
float fMinY;
float fMinZ;
float fMaxX;
float fMaxY;
float fMaxZ;
float fCenterX;
float fCenterY;
float fCenterZ;
cJSON *psIndices;
cJSON *psVertices;
cJSON *psTexCoords;
cJSON *psNormals;
cJSON* psBoundingBox;
float fScale;
cJSON *psRoot = cJSON_Parse(mesh);
if(!psRoot)
{
DBG_LOG(DBG_LOG_PREFIX"No root JSON");
return;
}
psIndices = cJSON_GetObjectItem(psRoot,"idx");
if(!psIndices)
{
DBG_LOG(DBG_LOG_PREFIX"No indices JSON");
cJSON_Delete(psRoot);
return;
}
psVertices = cJSON_GetObjectItem(psRoot,"vtxpos");
if(!psVertices)
{
DBG_LOG(DBG_LOG_PREFIX"No vertices JSON");
cJSON_Delete(psRoot);
return;
}
psTexCoords = cJSON_GetObjectItem(psRoot,"texcoord");
if(!psTexCoords)
{
DBG_LOG(DBG_LOG_PREFIX"No texcoords JSON");
cJSON_Delete(psRoot);
return;
}
psNormals = cJSON_GetObjectItem(psRoot,"normal");
if(!psNormals)
{
DBG_LOG(DBG_LOG_PREFIX"No normals JSON");
cJSON_Delete(psRoot);
return;
}
psBoundingBox = cJSON_GetObjectItem(psRoot, "bndbox");
if(!psBoundingBox)
{
DBG_LOG(DBG_LOG_PREFIX"No no bndbox JSON");
cJSON_Delete(psRoot);
return;
}
iNumIndices = cJSON_GetArraySize(psIndices);
pui16Indices = new uint16_t[iNumIndices];
for(idx = 0; idx < iNumIndices; ++idx)
{
cJSON* psIndex = cJSON_GetArrayItem(psIndices, idx);
pui16Indices[idx] = psIndex->valueint;
}
iNumVertices = cJSON_GetArraySize(psVertices) / 3; //GetArraySize will give the number of floats in vertex position array. Always XYZ.
pfVertices = new float[iNumVertices * 3];
pfTexCoords = new float[iNumVertices * 3];
pfNormals = new float[iNumVertices * 3];
for(vtx = 0; vtx < (iNumVertices * 3);)
{
cJSON* psVertex;
//.........这里部分代码省略.........
示例11: buildErrorMessage
void App42GameResponse::init()
{
if (_result != 200)
{
Util::app42Trace("App42Game failed result is %d", _result);
buildErrorMessage();
return;
}
cJSON *ptrBody = cJSON_Parse(_body.c_str());
cJSON* ptrApp42 = Util::getJSONChild("app42", ptrBody);
cJSON* ptrResponse = Util::getJSONChild("response", ptrApp42);
cJSON* ptrGames = Util::getJSONChild("games", ptrResponse);
if (ptrGames)
{
cJSON* ptrGame = Util::getJSONChild("game", ptrGames);
cJSON* child = ptrGame;
if (child->type == cJSON_Array)
{
child = child->child;
}
while (child != NULL && child->type == cJSON_Object)
{
App42Game app42Game;
app42Game.name = Util::getJSONString("name", child);
app42Game.description = Util::getJSONString("description", child);
games.push_back(app42Game);
child = child->next;
if (Util::getJSONChild("scores", ptrGame))
{
cJSON* ptrScores = Util::getJSONChild("scores", ptrGame);
cJSON* ptrScore = Util::getJSONChild("score", ptrScores);
cJSON* child = ptrScore;
if (child->type == cJSON_Array)
{
child = child->child;
}
while (child != NULL && child->type == cJSON_Object)
{
App42Score app42Score;
app42Score.setUserName(Util::getJSONString("userName", child));
app42Score.setRank(Util::getJSONDouble("rank", child));
app42Score.setScoreId(Util::getJSONString("scoreId", child));
app42Score.setScoreValue(Util::getJSONDouble("value", child));
app42Score.setCreatedOn(Util::getJSONString("createdOn", child));
cJSON* ptrFacebookProfile = Util::getJSONChild("facebookProfile", child);
if (ptrFacebookProfile)
{
app42Score.facebookProfile.setName(Util::getJSONString("name", ptrFacebookProfile));
app42Score.facebookProfile.setFbId(Util::getJSONString("id", ptrFacebookProfile));
app42Score.facebookProfile.setPicture(Util::getJSONString("picture", ptrFacebookProfile));
}
cJSON *ptrJsonDoc = Util::getJSONChild("jsonDoc", child);
if (ptrJsonDoc != NULL)
{
vector<JSONDocument> docArray;
if (ptrJsonDoc->type == cJSON_Array)
{
ptrJsonDoc = ptrJsonDoc->child;
}
while (ptrJsonDoc != NULL && ptrJsonDoc->type == cJSON_Object)
{
JSONDocument jsonDOC;
buildJsonDocument(ptrJsonDoc, &jsonDOC);
ptrJsonDoc = ptrJsonDoc->next;
docArray.push_back(jsonDOC);
}
app42Score.setJsonDocList(docArray);
}
scores.push_back(app42Score);
child = child->next;
}
}
}
}
else
{
setTotalRecords();
}
cJSON_Delete(ptrBody);
}
示例12: AnalysisJson
//.........这里部分代码省略.........
}
else sResOutput(">>> [ERR] RegisterAnswer in network.c strcasecmp CmdID "," >>>");
}
if (strcasecmp(item -> valuestring, "GroupFormationAnswer") == 0)
{
item = cJSON_GetObjectItem(res, "CmdID");
if( strcasecmp(status.SendCmdID, item->valuestring) == 0)
{
if ( ++Flags.temp == (status.MyTeamCount - 1) ){
Flags.temp = 0;
Flags.isSendGroupFormation = 1;
}
}
else sResOutput(">>> [ERR] GroupFormationAnswer in network.c strcasecmp CmdID "," >>>");
}
if (strcasecmp(item -> valuestring, "RecvMission") == 0)
{
item = cJSON_GetObjectItem(res, "CmdID");
if( strcasecmp(status.SendCmdID, item->valuestring) == 0)
{
if ( ++Flags.temp == (status.MyTeamCount - 1) ){
Flags.temp = 0;
Flags.isSendFinishedDownload = 1;
}
}
else sResOutput(">>> [ERR] RecvMission in network.c strcasecmp CmdID "," >>>");
}
if (strcasecmp(item -> valuestring, "Mission") == 0)
{
AnalysisMissionJson(buffer);
}
if (strcasecmp(item -> valuestring, "MissionDecision") == 0)
{
AnalysisMissionDecisionJson(buffer);
}
if (strcasecmp(item -> valuestring, "DecisionDownload") == 0)
{
AnalysisDecisionDownloadJson(buffer);
}
if (strcasecmp(item -> valuestring, "Adjust") == 0)
{
AnalysisAdjustJson(buffer);
}
if (strcasecmp(item -> valuestring, "Collection") == 0)
{
AnalysisCollectionJson(buffer);
}
if (strcasecmp(item -> valuestring, "ReInit") == 0)
{
AnalysisReInitJson(buffer);
}
if (strcasecmp(item -> valuestring, "Reset") == 0)
{
AnalysisResetJson(buffer);
}
if (strcasecmp(item -> valuestring, "ChangeMission") == 0)
{
if ( Flags.changeMissionf ){
AnalysisChangeMissionJson(buffer);
Flags.changeMissionf = 0;
}
}
if (strcasecmp(item -> valuestring, "PreAutoFormation") == 0)
{
}
if (strcasecmp(item -> valuestring, "StartMission") == 0)
{
if ( Flags.startMissionf ){
AnalysisStartMissionJson(buffer);
Flags.startMissionf = 0;
}
}
}
cJSON_Delete(res);
res = NULL;
}
示例13: entry_city_weibo
//.........这里部分代码省略.........
{
x_printf(W, "%s\n",data);
ok = REDIS_POOL_GAIN_FAILED;
return ok;
}
i = get_weidb_link_index();
host = g_weibo_cfg_file.weidb[i].host;
port = g_weibo_cfg_file.weidb[i].port;
task = (struct async_ctx *)pool_api_gain(loop, &weidb_pool, host, port);
if (NULL==task)
{
x_printf(W, "%s\n",data);
ok = HTTP_POOL_GAIN_FAILED;
return ok;
}
Weibo *wb = calloc(1, sizeof(Weibo));//开空间并初始化
if(!wb){
ok = API_NO_MEMORY;
goto ERROR_CITY;
}
wb->loop = loop;
/******判断传入进来的参数******/
if (NULL == data || 0 == size) {
ok = API_NO_DATA;
goto ERROR_CITY;
}else{
if (size > MAX_LEN_STRING){
ok = API_DATA_TOO_LONG;
goto ERROR_CITY;
}
}
/*data cjson parse*/
obj = cJSON_Parse (data);
if (NULL == obj) {
ok = API_INVALID_JSON;
goto ERROR_CITY;
}
wb->cjson = obj;
/*check regionCode*/
temp = cJSON_GetObjectItem(obj, "regionCode");
if (NULL==temp){
ok = API_INVALID_REGIONCODE;
goto ERROR_CITY;
}
wb->regionCode = temp->valuestring;
if(!wb->regionCode){
ok = API_INVALID_REGIONCODE;
goto ERROR_CITY;
}
/*check other*/
ok = parse_parments (wb, obj);
if (ok != API_OK){
goto ERROR_CITY;
}
wb->loop = loop;
wb->pool = redis_pool;
wb->redisPriority = redis_priority;
/*receiver:priority */
ok = weibo_set_receive(wb,loop,redis_receive,static_pool);
if (ok != API_OK){
goto ERROR_CITY;
}
/*bizid:weibo and bizid:senderInfo*/
ok = weibo_send_info(wb,loop,redis_weibo,redis_senderInfo,redis_expire,redis_pool);
if (ok != API_OK){
goto ERROR_CITY;
}
/*cJSON form turn into string form*/
body = cJSON_Print(obj);
if (!body){
ok = JSON_OP_FAIL;
goto ERROR_CITY;
}
/*data transmitting*/
ok=weibo_data_transmit(body,"weidb_city",loop,weidb_pool,task,host,port);
if (ok != API_OK){
goto ERROR_CITY;
}
free(body);
/*cant't free json,free it in callback*/
obj = NULL;
return ok;
ERROR_CITY:
if (obj){
cJSON_Delete(obj);
}
if(body){
free(body);
}
return ok;
}
示例14: entry_personal_weibo
//.........这里部分代码省略.........
redis_weibo = (struct async_ctx *)pool_api_gain(loop, &redis_pool,host,port);
if (NULL==redis_weibo)
{
x_printf(W, "%s\n",data);
ok = REDIS_POOL_GAIN_FAILED;
return ok;
}
redis_senderInfo = (struct async_ctx *)pool_api_gain(loop, &redis_pool,host,port);
if (NULL==redis_senderInfo)
{
x_printf(W, "%s\n",data);
ok = REDIS_POOL_GAIN_FAILED;
return ok;
}
redis_expire = (struct async_ctx *)pool_api_gain(loop, &redis_pool,host,port);
if (NULL==redis_expire)
{
x_printf(W, "%s\n",data);
ok = REDIS_POOL_GAIN_FAILED;
return ok;
}
i = get_weidb_link_index();
host = g_weibo_cfg_file.weidb[i].host;
port = g_weibo_cfg_file.weidb[i].port;
task = (struct async_ctx *)pool_api_gain(loop, &weidb_pool, host, port);
if (NULL==task)
{
x_printf(W, "%s\n",data);
ok = HTTP_POOL_GAIN_FAILED;
return ok;
}
/****判断传入进来的参数******/
if (NULL == data || 0 == size) {
ok = API_NO_DATA;
goto ERROR_PERSONAL;
}else {
if (size > MAX_LEN_STRING){
ok = API_DATA_TOO_LONG;
goto ERROR_PERSONAL;
}
}
/*data cjson parse*/
obj = cJSON_Parse (data);
if (NULL == obj) {
ok = API_INVALID_JSON;
goto ERROR_PERSONAL;
}
/*check parments*/
ok = parse_parments (&wb, obj);
if (ok != API_OK){
goto ERROR_PERSONAL;
}
strcpy(bizid,wb.bizid);//将生成的bizid,带回去
/*receiverAccountID:weiboPriority*/
ok = weibo_set_priority(wb.receiverAccountID,&wb,loop,redis_priority,redis_pool);
if (ok != API_OK){
goto ERROR_PERSONAL;
}
/*bizid:weibo and bizid:senderInfo*/
ok = weibo_send_info(&wb, loop,redis_weibo,redis_senderInfo,redis_expire,redis_pool);
if (ok != API_OK){
goto ERROR_PERSONAL;
}
/*cJSON form turn into string form*/
body = cJSON_Print(obj);
if (!body){
ok = JSON_OP_FAIL;
goto ERROR_PERSONAL;
}
/*data transmitting*/
ok = weibo_data_transmit(body,"weidb_personal",loop,weidb_pool,task,host,port);
if (ok != API_OK){
goto ERROR_PERSONAL;
}
free(body);
cJSON_Delete(obj);
return ok;
ERROR_PERSONAL:
if (obj){
cJSON_Delete(obj);
}
if(body){
free(body);
}
return ok;
}
示例15: SerializeReflection
//.........这里部分代码省略.........
root=cJSON_CreateObject();
cJSON_AddItemToObject(root, "ui32MajorVersion", cJSON_CreateNumber(psReflection->ui32MajorVersion));
cJSON_AddItemToObject(root, "ui32MinorVersion", cJSON_CreateNumber(psReflection->ui32MinorVersion));
cJSON_AddItemToObject(root, "ui32NumInputSignatures", cJSON_CreateNumber(psReflection->ui32NumInputSignatures));
for(uint32_t i = 0; i < psReflection->ui32NumInputSignatures; ++i)
{
std::string name;
name += "input";
AppendIntToString(name, i);
cJSON* obj = cJSON_CreateObject();
cJSON_AddItemToObject(root, name.c_str(), obj);
WriteInOutSignature(psReflection->psInputSignatures+i, obj);
}
cJSON_AddItemToObject(root, "ui32NumOutputSignatures", cJSON_CreateNumber(psReflection->ui32NumOutputSignatures));
for(uint32_t i = 0; i < psReflection->ui32NumOutputSignatures; ++i)
{
std::string name;
name += "output";
AppendIntToString(name, i);
cJSON* obj = cJSON_CreateObject();
cJSON_AddItemToObject(root, name.c_str(), obj);
WriteInOutSignature(psReflection->psOutputSignatures+i, obj);
}
cJSON_AddItemToObject(root, "ui32NumResourceBindings", cJSON_CreateNumber(psReflection->ui32NumResourceBindings));
for(uint32_t i = 0; i < psReflection->ui32NumResourceBindings; ++i)
{
std::string name;
name += "resource";
AppendIntToString(name, i);
cJSON* obj = cJSON_CreateObject();
cJSON_AddItemToObject(root, name.c_str(), obj);
WriteResourceBinding(psReflection->psResourceBindings+i, obj);
}
cJSON_AddItemToObject(root, "ui32NumConstantBuffers", cJSON_CreateNumber(psReflection->ui32NumConstantBuffers));
for(uint32_t i = 0; i < psReflection->ui32NumConstantBuffers; ++i)
{
std::string name;
name += "cbuf";
AppendIntToString(name, i);
cJSON* obj = cJSON_CreateObject();
cJSON_AddItemToObject(root, name.c_str(), obj);
WriteConstantBuffer(psReflection->psConstantBuffers+i, obj);
}
//psThisPointerConstBuffer is a cache. Don't need to write this out.
//It just points to the $ThisPointer cbuffer within the psConstantBuffers array.
for(uint32_t i = 0; i < psReflection->ui32NumClassTypes; ++i)
{
std::string name;
name += "classType";
AppendIntToString(name, i);
cJSON* obj = cJSON_CreateObject();
cJSON_AddItemToObject(root, name.c_str(), obj);
WriteClassType(psReflection->psClassTypes+i, obj);
}
for(uint32_t i = 0; i < psReflection->ui32NumClassInstances; ++i)
{
std::string name;
name += "classInst";
AppendIntToString(name, i);
cJSON* obj = cJSON_CreateObject();
cJSON_AddItemToObject(root, name.c_str(), obj);
WriteClassInstance(psReflection->psClassInstances+i, obj);
}
//psReflection->aui32TableIDToTypeID
//psReflection->aui32ConstBufferBindpointRemap
cJSON_AddItemToObject(root, "eTessPartitioning", cJSON_CreateNumber(psReflection->eTessPartitioning));
cJSON_AddItemToObject(root, "eTessOutPrim", cJSON_CreateNumber(psReflection->eTessOutPrim));
const char* jsonString = cJSON_Print(root);
cJSON_Delete(root);
return jsonString;
}