• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ cJSON_GetArrayItem函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: cjson_wrapper

 cjson_wrapper operator[](size_t index) const
 {
     return cjson_wrapper(cJSON_GetArrayItem(json_, index));
 }
开发者ID:coiled-coil,项目名称:cpp_json,代码行数:4,代码来源:cjson_wrapper.hpp


示例2: return

static stat_query_section_t *StatQuery_GetArraySection( stat_query_section_t *parent, int idx )
{
	return (stat_query_section_t *)cJSON_GetArrayItem( (cJSON *)parent, idx );
}
开发者ID:Clever-Boy,项目名称:qfusion,代码行数:4,代码来源:mm_query.c


示例3: cJSON_GetArrayItem

static const char *StatQuery_GetArrayString( stat_query_section_t *parent, int idx )
{
	cJSON *object = cJSON_GetArrayItem( (cJSON *)parent, idx );
	return StatQuery_JsonToString( object );
}
开发者ID:Clever-Boy,项目名称:qfusion,代码行数:5,代码来源:mm_query.c


示例4: PLUGNAME

int32_t PLUGNAME(_process_json)(char *forwarder,char *sender,int32_t valid,struct plugin_info *plugin,uint64_t tag,char *retbuf,int32_t maxlen,char *origjsonstr,cJSON *origjson,int32_t initflag,char *tokenstr)
{
    char endpoint[128],tagstr[512],*resultstr,*retstr = 0,*methodstr,*jsonstr,*destplugin,*submethod;
    cJSON *retjson,*json,*tokenobj; uint32_t nonce;
    struct applicant_info apply;
    retbuf[0] = 0;
    if ( tokenstr == 0 )
        tokenstr = "";
    if ( is_cJSON_Array(origjson) != 0 && cJSON_GetArraySize(origjson) == 2 )
        json = cJSON_GetArrayItem(origjson,0), jsonstr = cJSON_Print(json), _stripwhite(jsonstr,' ');
    else json = origjson, jsonstr = origjsonstr;
    if ( Debuglevel > 2 )
        printf("<<<<<<<<<<<< INSIDE relays PLUGIN! process %s [(%s).(%s)]\n",plugin->name,jsonstr,tokenstr);
    if ( initflag > 0 )
    {
        // configure settings
        RELAYS.readyflag = 1;
        plugin->allowremote = 1;
        strcpy(retbuf,"{\"result\":\"initflag > 0\"}");
    }
    else
    {
        if ( plugin_result(retbuf,json,tag) > 0 )
            return((int32_t)strlen(retbuf));
        resultstr = cJSON_str(cJSON_GetObjectItem(json,"result"));
        methodstr = cJSON_str(cJSON_GetObjectItem(json,"method"));
        destplugin = cJSON_str(cJSON_GetObjectItem(json,"destplugin"));
        submethod = cJSON_str(cJSON_GetObjectItem(json,"submethod"));
        if ( methodstr == 0 || methodstr[0] == 0 )
        {
            printf("(%s) has not method\n",jsonstr);
            return(0);
        }
        //fprintf(stderr,"RELAYS methodstr.(%s) (%s)\n",methodstr,jsonstr);
        if ( resultstr != 0 && strcmp(resultstr,"registered") == 0 )
        {
            plugin->registered = 1;
            strcpy(retbuf,"{\"result\":\"activated\"}");
        }
#ifdef INSIDE_MGW
        else if ( strcmp(methodstr,"msigaddr") == 0 )
        {
            char *devMGW_command(char *jsonstr,cJSON *json);
            if ( SUPERNET.gatewayid >= 0 )
                retstr = devMGW_command(jsonstr,json);
        }
#endif
        else
        {
            strcpy(retbuf,"{\"result\":\"relay command under construction\"}");
            if ( strcmp(methodstr,"list") == 0 )
                retstr = relays_jsonstr(jsonstr,json);
            else if ( strcmp(methodstr,"telepathy") == 0 )
            {
                sprintf(retbuf,"%s",jsonstr);
            }
            else if ( strcmp(methodstr,"busdata") == 0 )
            {
                retstr = busdata_sync(&nonce,jsonstr,cJSON_str(cJSON_GetObjectItem(json,"broadcast")),0);
                // {"plugin":"relay","method":"busdata","destplugin":"relay","submethod":"join","broadcast":"join","endpoint":""}
            }
            else if ( strcmp(methodstr,"allservices") == 0 )
            {
                if ( (retjson= serviceprovider_json()) != 0 )
                {
                    retstr = cJSON_Print(retjson), _stripwhite(retstr,' ');
                    free_json(retjson);
                    //printf("got.(%s)\n",retstr);
                } else printf("null serviceprovider_json()\n");
            }
            else if ( strcmp(methodstr,"protocol") == 0 || strcmp(methodstr,"allprotocols") == 0 )
            {
                if ( strcmp(methodstr,"protocol") == 0 && valid > 0 )
                    protocols_register(sender,jstr(json,"protocol"),jstr(json,"endpoint"),jint(json,"disconnect"));
                if ( (retjson= protocols_json(jstr(json,"protocol"))) != 0 )
                {
                    retstr = cJSON_Print(retjson), _stripwhite(retstr,' ');
                    free_json(retjson);
                } else printf("null protocols_json()\n");
            }
            else if ( strcmp(methodstr,"join") == 0 )
            {
                if ( SUPERNET.noncing == 0 )
                {
                    copy_cJSON(tagstr,cJSON_GetObjectItem(json,"tag"));
                    copy_cJSON(endpoint,cJSON_GetObjectItem(json,"endpoint"));
                    SUPERNET.noncing = 1;
                    if ( SUPERNET.iamrelay != 0 )
                    {
                        portable_thread_create((void *)calc_nonces,clonestr(endpoint));
                        sprintf(retbuf,"{\"result\":\"noncing\",\"endpoint\":\"%s\"}",endpoint);
                    }
                    //fprintf(stderr,"join or nonce.(%s)\n",retbuf);
                }
            }
            else if ( strcmp(methodstr,"nonce") == 0 )
            {
                char endpoint[512],sender[64],destpoint[512],relaypoint[512],globalpoint[512],noncestr[512];
                memset(&apply,0,sizeof(apply));
                copy_cJSON(destpoint,cJSON_GetObjectItem(json,"destpoint"));
//.........这里部分代码省略.........
开发者ID:ychaim,项目名称:libjl777,代码行数:101,代码来源:relays777.c


示例5: MM_ReadJails

void MM_ReadJails(const char *fileData)
{
	cJSON * root = cJSON_Parse(fileData);
	int len = root ? cJSON_GetArraySize(root) : 0;

	for (int i = 0; i < len; i++)
	{
		cJSON *item = cJSON_GetArrayItem(root, i);
		if (!item)
		{
			G_LogPrintf(__FUNCTION__"(): item %i is NULL, skipping.\n", i);
			continue;
		}

		cJSON *origin = cJSON_GetObjectItem(item, "origin");
		if (!origin)
		{
			G_LogPrintf(__FUNCTION__"(): item %i has NULL origin, skipping.\n", i);
			continue;
		}

		if (cJSON_GetArraySize(origin) != 3)
		{
			G_LogPrintf(__FUNCTION__"(): item %i has corrupted origin, skipping.\n", i);
			continue;
		}

		float origin_v[3] = { 0 };
		qboolean _continue = qfalse;
		for (int j = 0; j < 3; j++)
		{
			cJSON *origin_m = cJSON_GetArrayItem(origin, j);
			if (origin_m->type == cJSON_Number)
				origin_v[j] = cJSON_GetArrayItem(origin, j)->valuedouble;
			else
			{
				G_LogPrintf(__FUNCTION__"(): item %i has corrupted origin axis, skipping.\n", i);
				_continue = qtrue;
			}
		}
		if (_continue) continue;

		cJSON *angles = cJSON_GetObjectItem(item, "angles");
		if (!angles)
		{
			G_LogPrintf(__FUNCTION__"(): item %i has NULL angles, skipping.\n", i);
			continue;
		}

		if (cJSON_GetArraySize(angles) != 3)
		{
			G_LogPrintf(__FUNCTION__"(): item %i has corrupted angles, skipping.\n", i);
			continue;
		}

		float angles_v[3] = { 0 };
		for (int j = 0; j < 3; j++)
		{
			cJSON *angles_m = cJSON_GetArrayItem(angles, j);
			if (angles_m->type == cJSON_Number)
				angles_v[j] = cJSON_GetArrayItem(angles, j)->valuedouble;
			else
			{
				G_LogPrintf(__FUNCTION__"(): item %i has corrupted angles axis, skipping.\n", i);
				_continue = qtrue;
			}
		}
		if (_continue) continue;

		jails_add(origin_v, angles_v);
	}

	cJSON_Delete(root);
}
开发者ID:spior,项目名称:Makermod,代码行数:74,代码来源:mm_jail.c


示例6: _load_config

static int _load_config()
{
	cJSON *config = NULL;
	cJSON *data = NULL;
	cJSON *elm = NULL;
	cJSON *startTime = NULL;
	cJSON *command = NULL;
	int cnt = 0;
	int index = 0;
	int hour,min,second;
	int ret = OK;
	
	if (NULL != task)
	{
		free(task);
		task = NULL;
	}

	config = _get_JSON_from_file(CONFIG_FILE_PATH);
	if (NULL == config)
	{
		LOG_ERR("get config errer");
		ret = ERROR;
		goto leave;
	}

	/* attendtion free */
	PRINTF("data = %s", cJSON_Print(config));	
	data = cJSON_GetObjectItem(config, "data");
	cnt = cJSON_GetArraySize(data);

	task = (TASK_ENTRY *)malloc(sizeof(TASK_ENTRY)*cnt);
	if (NULL == task)
	{
		LOG_ERR("malloc error!");
		ret = ERROR;
		goto leave;
	}
	
	for(index = 0; index < cnt; index++)
	{
		elm = cJSON_GetArrayItem(data, index);
		startTime = cJSON_GetObjectItem(elm, "startTime");
		if( startTime != NULL && startTime->type == cJSON_String )
		{
			sscanf(startTime->valuestring, "%d:%d:%d", &hour, &min, &second);
			task[index].startTime = hour * 60 * 60 + min * 60 + second;
		}
		
		command = cJSON_GetObjectItem(elm, "command");
		if( command != NULL && command->type == cJSON_String )
		{
			if(strlen(command->valuestring) < MAX_COMMAND_LENGTH)
			{
				strcpy(task[index].command, command->valuestring);
			}
			else
			{
				LOG_ERR("command %s size %d error!", command->valuestring, strlen(command->valuestring));
				_log_to_file(ERROR_LOG_FILE_PATH, "command %s size %d error!",	command->valuestring, strlen(command->valuestring));
			}
		}
	}

	_quick_sort(0, cnt - 1, task);
	task_index = 0;
	task_MAX = cnt;
	
#ifdef LOG_DEBUG
	for(index = 0; index < cnt; index++)
	{
		PRINTF("%02d:%02d:%02d	%s", task[index].startTime/3600, (task[index].startTime % 3600)/60, task[index].startTime%60, task[index].command);
	}
#endif

leave:
	if(config)
		cJSON_Delete(config);
	
	return ret;
}
开发者ID:jack2949,项目名称:sheduled,代码行数:81,代码来源:main.c


示例7: PLUGNAME

int32_t PLUGNAME(_process_json)(char *forwarder,char *sender,int32_t valid,struct plugin_info *plugin,uint64_t tag,char *retbuf,int32_t maxlen,char *jsonstr,cJSON *json,int32_t initflag,char *tokenstr)
{
    char *resultstr,*methodstr,zerobuf[1],*coinstr,*str = 0; cJSON *array,*item; int32_t i,n,j = 0; struct coin777 *coin; struct destbuf tmp;
    retbuf[0] = 0;
    if ( initflag > 0 )
    {
        if ( json != 0 )
        {
            COINS.argjson = cJSON_Duplicate(json,1);
            COINS.slicei = get_API_int(cJSON_GetObjectItem(json,"slice"),0);
            if ( (array= cJSON_GetObjectItem(json,"coins")) != 0 && (n= cJSON_GetArraySize(array)) > 0 )
            {
                for (i=j=0; i<n; i++)
                {
                    item = cJSON_GetArrayItem(array,i);
                    coinstr = cJSON_str(cJSON_GetObjectItem(item,"name"));
                    if ( coinstr != 0 && coinstr[0] != 0 && (coin= coin777_find(coinstr,0)) == 0 )
                    {
                        printf("CALL coin777_create.(%s) (%s)\n",coinstr,cJSON_Print(item));
                        coin777_create(coinstr,item);
                    }
                }
            }
        } else strcpy(retbuf,"{\"result\":\"no JSON for init\"}");
        COINS.readyflag = 1;
        plugin->allowremote = 1;
        //plugin->sleepmillis = 1;
    }
    else
    {
        if ( plugin_result(retbuf,json,tag) > 0 )
            return((int32_t)strlen(retbuf));
        resultstr = cJSON_str(cJSON_GetObjectItem(json,"result"));
        methodstr = cJSON_str(cJSON_GetObjectItem(json,"method"));
        coinstr = cJSON_str(cJSON_GetObjectItem(json,"coin"));
        if ( methodstr == 0 || methodstr[0] == 0 )
        {
            printf("(%s) has not method\n",jsonstr);
            return(0);
        }
        //printf("COINS.(%s) for (%s) (%s)\n",methodstr,coinstr!=0?coinstr:"",jsonstr);
        if ( resultstr != 0 && strcmp(resultstr,"registered") == 0 )
        {
            plugin->registered = 1;
            strcpy(retbuf,"{\"result\":\"activated\"}");
        }
        else
        {
            zerobuf[0] = 0;
            str = 0;
            //printf("INSIDE COINS.(%s) methods.%ld\n",jsonstr,sizeof(coins_methods)/sizeof(*coins_methods));
            copy_cJSON(&tmp,cJSON_GetObjectItem(json,"NXT")), safecopy(sender,tmp.buf,32);
            if ( coinstr == 0 )
                coinstr = zerobuf;
            else coin = coin777_find(coinstr,1);
#ifdef INSIDE_MGW
            if ( strcmp(methodstr,"acctpubkeys") == 0 )
            {
                if ( SUPERNET.gatewayid >= 0 )
                {
                    if ( coinstr[0] == 0 )
                        strcpy(retbuf,"{\"result\":\"need to specify coin\"}");
                    else if ( (coin= coin777_find(coinstr,1)) != 0 )
                    {
                        int32_t MGW_publish_acctpubkeys(char *coinstr,char *str);
                        char *get_msig_pubkeys(char *coinstr,char *serverport,char *userpass);
                        if ( (str= get_msig_pubkeys(coin->name,coin->serverport,coin->userpass)) != 0 )
                        {
                            MGW_publish_acctpubkeys(coin->name,str);
                            strcpy(retbuf,"{\"result\":\"published and processed acctpubkeys\"}");
                            free(str), str= 0;
                        } else sprintf(retbuf,"{\"error\":\"no get_msig_pubkeys result\",\"method\":\"%s\"}",methodstr);
                    } else sprintf(retbuf,"{\"error\":\"no coin777\",\"method\":\"%s\"}",methodstr);
                } else sprintf(retbuf,"{\"error\":\"gateway only method\",\"method\":\"%s\"}",methodstr);
            }
            else if ( strcmp(methodstr,"gotmsigaddr") == 0 )
            {
                if ( SUPERNET.gatewayid < 0 )
                    printf("GOTMSIG.(%s)\n",jsonstr);
            }
            else
#endif
                sprintf(retbuf,"{\"error\":\"unsupported method\",\"method\":\"%s\"}",methodstr);
        }
    }
    //printf("<<<<<<<<<<<< INSIDE PLUGIN.(%s) initflag.%d process %s slice.%d\n",SUPERNET.myNXTaddr,initflag,plugin->name,COINS.slicei);
    return(plugin_copyretstr(retbuf,maxlen,str));
}
开发者ID:Bitcoinsulting,项目名称:libjl777,代码行数:88,代码来源:coins777_main.c


示例8: getPluginWebIncludes

/*
  * This function provides a way of opening and parsing out
  *an include file named "Client.json" in each plugin
  *directory for the benefit of the webbrowser
  */
int
getPluginWebIncludes (struct evbuffer* target,
                      const char* pluginDirName)
{
    if (!target || !pluginDirName)
    {
        doLog (ERROR, LOG_COMP, _("Invalid use of getPluginWebIncludes()."));
        return -1;
    }
    
#ifndef WEB_PLUGIN_DIR
    doLog (ERROR, LOG_COMP, _("WEB_PLUGIN_DIR not provided at compile time."));
    return -1;
#endif

    char pluginIncludePath[256];
    snprintf (pluginIncludePath,
              256,
              "%s/%s/Client.json",
              WEB_PLUGIN_PATH,
              pluginDirName);

    FILE* includeFile = fopen (pluginIncludePath, "rb");
    if (includeFile)
    {

        /* Get file size first */
        fseek (includeFile, 0L, SEEK_END);
        size_t sz = ftell (includeFile);
        fseek (includeFile, 0L, SEEK_SET);

        char* includeFileContent = malloc (sizeof( char ) * sz);
        if (!includeFileContent)
        {
            doLog (ERROR, LOG_COMP, _("Unable to allocate memory to accommodate include file for parsing."));
            fclose (includeFile);
            return -1;
        }
        fread (includeFileContent, sizeof( char ) * sz, 1, includeFile);

        cJSON* includeFileParsed = cJSON_Parse (includeFileContent);
        if (!includeFileParsed)
        {
            doLog (ERROR, LOG_COMP, _("Unable to parse JSON from include file."));
            fclose (includeFile);
            free (includeFileContent);
            return -1;
        }

        /* Done with string after parsing */
        free (includeFileContent);

        /* Make comment in HTML */
        evbuffer_add_printf (target, "\t\t<!-- Includes for %.50s -->\n",
                             pluginDirName);

        /* PARSE! */
        int i;

        cJSON* jsArr = cJSON_GetObjectItem (includeFileParsed, "js");
        if (jsArr && jsArr->type == cJSON_Array)
            for (i = 0; i < cJSON_GetArraySize (jsArr); ++i)
            {
                cJSON* jsItem = cJSON_GetArrayItem (jsArr, i);
                if (jsItem && jsItem->type == cJSON_String)
                    evbuffer_add_printf (
                        target,
                        "\t\t<script type=\"text/javascript\" src=\"../plugins/%.50s/%.50s\"></script>\n",
                        pluginDirName,
                        jsItem->valuestring);
            }

        cJSON* cssArr = cJSON_GetObjectItem (includeFileParsed, "css");
        if (cssArr && cssArr->type == cJSON_Array)
            for (i = 0; i < cJSON_GetArraySize (cssArr); ++i)
            {
                cJSON* cssItem = cJSON_GetArrayItem (cssArr, i);
                if (cssItem && cssItem->type == cJSON_String)
                    evbuffer_add_printf (
                        target,
                        "\t\t<link rel=\"stylesheet\" type=\"text/css\" href=\"../plugins/%.50s/%.50s\" />\n",
                        pluginDirName,
                        cssItem->valuestring);
            }

        /* Line break */
        evbuffer_add_printf (target, "\n");

        /* Free JSON */
        cJSON_Delete (includeFileParsed);

    }
    else
    {
        doLog (WARNING, LOG_COMP, _("Unable to open %s. No includes added."), pluginIncludePath);
//.........这里部分代码省略.........
开发者ID:jackoalan,项目名称:LightShoppe-Daemon,代码行数:101,代码来源:PluginLoader.c


示例9: GetScoreBlock

void LeaderboardStorage::Tick(double TimePassed)
{
    if( m_pWebRequestObject )
        m_pWebRequestObject->Tick();
    
    m_TimeSinceLastRequestSent += (float)TimePassed;
    if( m_TimeSinceLastRequestSent > m_MaxTimeToWaitToWebResponse )
    {
        m_pWebRequestObject->Reset();
    }
    
    if( m_pWebRequestObject->DidSomethingGoWrong() )
        return;

    if( m_RequestedBoardID >= 0 && m_pWebRequestObject->IsBusy() == false && m_pWebRequestObject->GetResult() == 0 )
        GetScoreBlock();

    // invalidate all blocks older than 3 minutes.
    if( true )
    {
        for( int i=0; i<NumLeaderboardStorageBlocksCached; i++ )
        {
            if( m_Blocks[i].m_InUse )
            {
                double age = MyTime_GetSystemTime() - m_Blocks[i].m_TimeRetrieved;
                if( age > 3*60 )
                    m_Blocks[i].m_InUse = false;
            }
        }
    }

    // if we received anything from the web, parse it and store it.
    if( m_pWebRequestObject->IsBusy() == false )
    {
        char* result = m_pWebRequestObject->GetResult();
        if( result )
        {
            cJSON* root = cJSON_Parse( result );
            if( root )
            {
                cJSON* obj;

                obj = cJSON_GetObjectItem( root, "NumEntries" );
                if( obj )
                {
                    g_pGame->m_pLeaderboardStorage->m_TotalPlayers[m_RequestedBoardID] = obj->valueint;
                }

                // read in "UserOffset", only returned if we are looking for a user.
                obj = cJSON_GetObjectItem( root, "UserOffset" );
                if( obj )
                {
                    m_UserIndices[m_RequestedBoardID] = obj->valueint - 1;
                }

                int blockoffset = m_RequestedOffset;
                obj = cJSON_GetObjectItem( root, "BlockOffset" );
                if( obj )
                {
                    blockoffset = obj->valueint;
                }

                int boardid = m_RequestedBoardID;

                // find a block of names and scores to store this info into.
                int blocktouse = FindDuplicateBlockOrReturnNew( blockoffset, boardid );
                m_Blocks[blocktouse].m_InUse = true;
                m_Blocks[blocktouse].m_Offset = blockoffset;
                m_Blocks[blocktouse].m_BoardID = boardid;
                m_Blocks[blocktouse].m_TimeRetrieved = MyTime_GetSystemTime();
                m_Blocks[blocktouse].m_NumEntriesInBlock = 0;

                cJSON* NameArray = cJSON_GetObjectItem( root, "UserNames" );
                if( NameArray )
                {
                    m_Blocks[blocktouse].m_NumEntriesInBlock = cJSON_GetArraySize( NameArray );

                    for( int i=0; i<m_Blocks[blocktouse].m_NumEntriesInBlock; i++ )
                    {
                        LeaderboardBlockEntry* pPlayer = &m_Blocks[blocktouse].m_Entries[i];
                        cJSON* temp;
                        temp = cJSON_GetArrayItem( NameArray, i ); if( temp ) strcpy_s( pPlayer->m_Username, 15+1, temp->valuestring );

                        // if we find our own name, then store it's index.
                        if( _stricmp( temp->valuestring, g_pGame->m_pProfileManager->m_CurrentProfile->m_Username ) == 0 )
                            m_UserIndices[m_RequestedBoardID] = blockoffset + i;
                    }

                    // if we got names, we should get Scores.
                    cJSON* ScoreArray = cJSON_GetObjectItem( root, "Scores" );
                    if( ScoreArray )
                    {
                        int numitems = cJSON_GetArraySize( ScoreArray );

                        for( int i=0; i<numitems; i++ )
                        {
                            LeaderboardBlockEntry* pPlayer = &m_Blocks[blocktouse].m_Entries[i];
                            cJSON* temp;
                            temp = cJSON_GetArrayItem( ScoreArray, i );
                            if( temp )
//.........这里部分代码省略.........
开发者ID:pmeneguzzi,项目名称:SharedGameCode,代码行数:101,代码来源:LeaderboardStorage.cpp


示例10: BaiduPCS_ResetError

PCSFileList *BaiduPCS_ListRemoteDir(BaiduPCS *api, const char *path) {
//{{{
    PCSFileList *list       = NULL;
    PCSFile *file           = NULL;
    HttpClient *client      = api->client;
    char *url_buffer        = api->util_buffer0;
    const char *token       = api->token;
    const char *error       = NULL;
    const char *response    = NULL;
    char *path_encode       = NULL;
    cJSON *json             = NULL;
    cJSON *array            = NULL;
    cJSON *item             = NULL;
    int i                   = 0;
    int length              = 0;

    BaiduPCS_ResetError(api); 

    list          = PCSFileList_New();

    path_encode = curl_easy_escape(client->curl, path, 0);
    sprintf(url_buffer, "https://pcs.baidu.com/rest/2.0/pcs/file?"
           "access_token=%s"
           "&method=list"
           "&path=%s", token, path_encode);
    curl_free(path_encode);

#ifdef DEBUG
    fprintf(stderr, "request %s\n", url_buffer);
#endif

    HttpClient_Init(client);
    HttpClient_Get(client, url_buffer);

    MAKE_JSON();

    item = cJSON_GetObjectItem(json, "list");
    if (item == NULL || item->type != cJSON_Array) {
        BaiduPCS_ThrowError(api, "can't find json.list");
        goto free;
    }

    array = item;
    length = cJSON_GetArraySize(array);
    
    for (i = 0; i < length; i ++) {
        item = cJSON_GetArrayItem(array, i);
        if (item == NULL || item->type != cJSON_Object) {
            BaiduPCS_ThrowError(api, "json.list.item is not object");
            goto free;
        }

        file = PCSFile_New();
        PCSFileList_Prepend(list, file);
        _BaiduPCS_Json2File(api, file, item);
        if (BaiduPCS_GetError(api) != NULL) {
        }
    }
       
free:

    if (json != NULL) {
        cJSON_Delete(json);
    }

    return list;
} 
开发者ID:William-Wai,项目名称:baidu_pcs_cli,代码行数:67,代码来源:pcs.c


示例11: buildErrorMessage

void App42UserResponse::init()
{
    if(_result != 200)
    {
        Util::app42Trace("App42User failed result is %d", _result);
        buildErrorMessage();
        return;
    }
    // parse the body
    cJSON *ptrBody = cJSON_Parse(_body.c_str());
    cJSON* ptrApp42 = Util::getJSONChild("app42", ptrBody);
    cJSON* ptrResponse = Util::getJSONChild("response", ptrApp42);
    cJSON* ptrUsers = Util::getJSONChild("users", ptrResponse);
    if (ptrUsers)
    {
        cJSON* ptrUser = Util::getJSONChild("user", ptrUsers);
        
        if (ptrUser)
        {
            cJSON* child = ptrUser;
            if(child->type == cJSON_Array)
            {
                child = child->child;
            }
            
            while(child != NULL && child->type == cJSON_Object)
            {
                App42User app42User;
                app42User.userName = Util::getJSONString("userName", child);
                app42User.email = Util::getJSONString("email", child);
                app42User.isAccountLocked = Util::getJSONInt("accountLocked", child);
                app42User.sessionId = Util::getJSONInt("sessionId", child);
                
                cJSON* ptrUserProfile = Util::getJSONChild("profile", child);
                if (ptrUserProfile)
                {
                    app42User.profile = buildUserProfile(ptrUserProfile);
                }
                
                cJSON* ptrUserRoles = Util::getJSONChild("role", child);
                if (ptrUserRoles)
                {
                    cJSON* childRole = ptrUserRoles;

                    if (childRole->type == cJSON_Array)
                    {
                        int size = cJSON_GetArraySize(childRole);
                        for (int i=0; i<size; i++)
                        {
                            cJSON *item = cJSON_GetArrayItem(childRole, i);
                            app42User.roleList.push_back(item->valuestring);
                        }
                    }
                }
                
                users.push_back(app42User);
                child = child->next;
            }
        }
    }
    else
    {
        setTotalRecords();
    }
    
    cJSON_Delete(ptrBody);
}
开发者ID:RajeevRShephertz,项目名称:App42_Cocos2dX_SDK,代码行数:67,代码来源:App42UserResponse.cpp


示例12: cJSON_GetArrayItem

// i ==>index
cJSON *JSONNode::getArrayItem(cJSON *head, int index)
{
	if(index >= getArraySize(head)) return NULL;
	return cJSON_GetArrayItem(head, index);
}
开发者ID:HanWenfang,项目名称:MumanPlatform,代码行数:6,代码来源:JSONNode.cpp


示例13: JSONToPstatBin

OicSecPstat_t * JSONToPstatBin(const char * jsonStr, const bool isIncResName)
{
    if(NULL == jsonStr)
    {
        return NULL;
    }

    OCStackResult ret = OC_STACK_ERROR;
    OicSecPstat_t *pstat = NULL;
    cJSON *jsonPstat = NULL;
    cJSON *jsonObj = NULL;

    unsigned char base64Buff[sizeof(((OicUuid_t*) 0)->id)] = {};
    uint32_t outLen = 0;
    B64Result b64Ret = B64_OK;

    cJSON *jsonRoot = cJSON_Parse(jsonStr);
    VERIFY_NON_NULL(TAG, jsonRoot, INFO);

    if(isIncResName)
    {
        jsonPstat = cJSON_GetObjectItem(jsonRoot, OIC_JSON_PSTAT_NAME);
    }
    else
    {
        jsonPstat = jsonRoot;
    }
    VERIFY_NON_NULL(TAG, jsonPstat, INFO);

    pstat = (OicSecPstat_t*)OICCalloc(1, sizeof(OicSecPstat_t));
    VERIFY_NON_NULL(TAG, pstat, INFO);
    jsonObj = cJSON_GetObjectItem(jsonPstat, OIC_JSON_ISOP_NAME);
    VERIFY_NON_NULL(TAG, jsonObj, ERROR);
    VERIFY_SUCCESS(TAG, (cJSON_True == jsonObj->type || cJSON_False == jsonObj->type) , ERROR);
    pstat->isOp = jsonObj->valueint;

    jsonObj = cJSON_GetObjectItem(jsonPstat, OIC_JSON_DEVICE_ID_NAME);
    VERIFY_NON_NULL(TAG, jsonObj, ERROR);
    VERIFY_SUCCESS(TAG, cJSON_String == jsonObj->type, ERROR);
    b64Ret = b64Decode(jsonObj->valuestring, strlen(jsonObj->valuestring), base64Buff,
                sizeof(base64Buff), &outLen);
    VERIFY_SUCCESS(TAG, (b64Ret == B64_OK && outLen <= sizeof(pstat->deviceID.id)), ERROR);
    memcpy(pstat->deviceID.id, base64Buff, outLen);

    jsonObj = cJSON_GetObjectItem(jsonPstat, OIC_JSON_COMMIT_HASH_NAME);
    VERIFY_NON_NULL(TAG, jsonObj, ERROR);
    VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR);
    pstat->commitHash  = jsonObj->valueint;

    jsonObj = cJSON_GetObjectItem(jsonPstat, OIC_JSON_CM_NAME);
    VERIFY_NON_NULL(TAG, jsonObj, ERROR);
    VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR);
    pstat->cm  = (OicSecDpm_t)jsonObj->valueint;

    jsonObj = cJSON_GetObjectItem(jsonPstat, OIC_JSON_OM_NAME);
    VERIFY_NON_NULL(TAG, jsonObj, ERROR);
    VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR);
    pstat->om  = (OicSecDpom_t)jsonObj->valueint;

    jsonObj = cJSON_GetObjectItem(jsonPstat, OIC_JSON_SM_NAME);
    VERIFY_NON_NULL(TAG, jsonObj, ERROR);
    if (cJSON_Array == jsonObj->type)
    {
        pstat->smLen = cJSON_GetArraySize(jsonObj);
        size_t idxx = 0;
        VERIFY_SUCCESS(TAG, pstat->smLen != 0, ERROR);
        pstat->sm = (OicSecDpom_t*)OICCalloc(pstat->smLen, sizeof(OicSecDpom_t));
        VERIFY_NON_NULL(TAG, pstat->sm, ERROR);
        do
        {
            cJSON *jsonSm = cJSON_GetArrayItem(jsonObj, idxx);
            VERIFY_NON_NULL(TAG, jsonSm, ERROR);
            pstat->sm[idxx] = (OicSecDpom_t)jsonSm->valueint;
        }while ( ++idxx < pstat->smLen);
    }
    ret = OC_STACK_OK;

exit:
    cJSON_Delete(jsonRoot);
    if (OC_STACK_OK != ret)
    {
        OC_LOG (ERROR, TAG, "JSONToPstatBin failed");
        DeletePstatBinData(pstat);
        pstat = NULL;
    }
    return pstat;
}
开发者ID:chetan336,项目名称:iotivity,代码行数:87,代码来源:pstatresource.c


示例14: jdoublei

double jdoublei(cJSON *json,int32_t i)
{
    if ( json != 0 )
        return(get_API_float(cJSON_GetArrayItem(json,i)));
    else return(0.);
}
开发者ID:Bitcoinsulting,项目名称:libjl777,代码行数:6,代码来源:cJSON.c


示例15: _setConfigurations

void _setConfigurations(cJSON *root, s_config *config, char *http_packet)
{
	cJSON *valueSetObj= cJSON_CreateObject();
	cJSON *attribute;
	cJSON *key;
	cJSON *item;
	int array_size;
	int i;
	char cmd[MAX_BUF];
	char result[MAX_BUF];
	char ErrMesg[B_5_BUF];
	cJSON *transaction_id = cJSON_GetObjectItem(root, "transaction_id");
	char *conf_version;
	char *radio_index;
	char *profile_index;
	char *status;
	int flag =0;
	if(!transaction_id) {
		debug(LOG_ERR, "Can not find transaction_id parameter: %s", cJSON_GetErrorPtr());
		create_http_json(valueSetObj, NULL, RESPONSE, SETCONFIGURATIONS, "failed", "3", "Missing parameter:{transaction_id}", config->sn, http_packet);
		return;

	}
	cJSON *valueSet = cJSON_GetObjectItem(root, "valueSet");
	if(!valueSet) {
		debug(LOG_ERR, "Get valueSet faild[%s]", cJSON_GetErrorPtr());
		create_http_json(valueSetObj, transaction_id->valuestring, RESPONSE, SETCONFIGURATIONS, "failed", "3", "Missing parameter:{valueSet}", config->sn, http_packet);
		return;
	}
	/*
	if((key = cJSON_GetObjectItem(valueSet, "conf_version")) == NULL || (conf_version = key->valuestring) == NULL) {
		create_http_json(valueSetObj, transaction_id->valuestring, RESPONSE, SETCONFIGURATIONS, "failed", "3", "Missing parameter:{conf_version}", config->sn, http_packet);
		return;
	}
	*/
	ErrMesg[0]=0;
	//setDeviceInfo//
	{
		if((attribute = cJSON_GetObjectItem(valueSet, "setDeviceInfo")) != NULL) {
			if((key = cJSON_GetObjectItem(attribute, "apname")) != NULL && key->valuestring != NULL) {
					/*snprintf(cmd, MAX_BUF, "config apname %s\n", key->valuestring);
					if(set_config(cmd, result)) 
						strcpy(ErrMesg, result);
					*/
					set_apname(key->valuestring, result, sizeof(result)/sizeof(result[0]));
				}
		}
	}
	//setRadioInfo//
	{
		if((attribute = cJSON_GetObjectItem(valueSet, "setRadioInfo")) != NULL) {
			array_size = cJSON_GetArraySize(attribute);
			debug(LOG_DEBUG, "Array size of paras is %d",array_size);
 			for(i=0; i< array_size; i++) {
				item = cJSON_GetArrayItem(attribute, i);
				//debug(LOG_DEBUG, "%s\n",item->valuestring);
				if((key = cJSON_GetObjectItem(item, "radio_index")) == NULL || (radio_index = radio_keywords[parse_radio_keywords(key->valuestring)].value) == NULL) {
					create_http_json(valueSetObj, transaction_id->valuestring, RESPONSE, SETCONFIGURATIONS, "failed", "3", "Missing parameter:{radio_index}", config->sn, http_packet);
					return;
				}
				/*
				if((key = cJSON_GetObjectItem(item, "radio")) != NULL && key->valuestring != NULL) {
					snprintf(cmd, MAX_BUF, "config interface wlan %s radio %s\n", cJSON_GetObjectItem(item, "radio_index")->valuestring, key->valuestring);
					if(set_config(cmd, result)) 
						strcpy(ErrMesg, result);
					//debug(LOG_INFO, "result is %d", strlen(result));
				}
				*/
				if((key = cJSON_GetObjectItem(item, "mode")) != NULL && key->valuestring != NULL) {
					/*snprintf(cmd, MAX_BUF, "config interface wlan %s mode %s\n", cJSON_GetObjectItem(item, "radio_index")->valuestring, key->valuestring);
					if(set_config(cmd, result)) 
						strcpy(ErrMesg, result);
					*/
			
					set_mode(atoi(radio_index), key->valuestring, result, sizeof(result)/sizeof(result[0]));
					strcpy(ErrMesg, result);
				}
				
				if((key = cJSON_GetObjectItem(item, "power")) != NULL && key->valuestring != NULL) {
					/*
					snprintf(cmd, MAX_BUF, "config interface wlan %s power %s\n", cJSON_GetObjectItem(item, "radio_index")->valuestring, key->valuestring);
					if(set_config(cmd, result)) 
						strcpy(ErrMesg, result);
					*/
					set_power(atoi(radio_index), key->valuestring, result, sizeof(result)/sizeof(result[0]));
					strcpy(ErrMesg, result);
				}
				
				if((key = cJSON_GetObjectItem(item, "channel")) != NULL && key->valuestring != NULL) {
					/*
					snprintf(cmd, MAX_BUF, "config interface wlan %s channel %s\n", cJSON_GetObjectItem(item, "radio_index")->valuestring, key->valuestring);
					if(set_config(cmd, result)) 
						strcpy(ErrMesg, result);
					*/
					set_channel(atoi(radio_index), key->valuestring, result, sizeof(result)/sizeof(result[0]));
					strcpy(ErrMesg, result);
				}
				if((key = cJSON_GetObjectItem(item, "channelwidth")) != NULL && key->valuestring != NULL) {
					/*
					snprintf(cmd, MAX_BUF, "config interface wlan %s channelwidth %s\n", cJSON_GetObjectItem(item, "radio_index")->valuestring, key->valuestring);
//.........这里部分代码省略.........
开发者ID:lonegoli,项目名称:R7000,代码行数:101,代码来源:cuci.c


示例16: if

cJSON *jitem(cJSON *array,int32_t i) { if ( array != 0 && is_cJSON_Array(array) != 0 && cJSON_GetArraySize(array) > i ) return(cJSON_GetArrayItem(array,i)); return(0); }
开发者ID:Bitcoinsulting,项目名称:libjl777,代码行数:1,代码来源:cJSON.c


示例17: _getMonitor

void _getMonitor(cJSON *root, s_config *config, char *http_packet)
{
	char tmp_value[32];
	int flag = 0;
	cJSON *valueSetObj= cJSON_CreateObject();
	cJSON *package;
	cJSON *list;
	cJSON *transaction_id = cJSON_GetObjectItem(root, "transaction_id");
	if(!transaction_id) {
		debug(LOG_ERR, "Can not find transaction_id parameter: %s", cJSON_GetErrorPtr());
		create_http_json(valueSetObj, 0, RESPONSE, GETMONITOR, "failed", "3", "Missing parameter:{transaction_id}", config->sn, http_packet);
		return;

	}

	cJSON *valueSet = cJSON_GetObjectItem(root, "valueSet");
	if(!valueSet) {
		debug(LOG_ERR, "Can not find valueset parameter: %s", cJSON_GetErrorPtr());
		create_http_json(valueSetObj, transaction_id->valuestring, RESPONSE, GETMONITOR, "failed", "3", "Missing parameter:{valueSet}", config->sn, http_packet);
		return;
	}

	cJSON *monitors = cJSON_GetObjectItem(valueSet, "monitors");
	if(!monitors) {
		debug(LOG_ERR, "Can not find monitor parameter: %s", cJSON_GetErrorPtr());
		create_http_json(valueSetObj, transaction_id->valuestring, RESPONSE, GETMONITOR, "failed", "3", "Missing parameter:{monitors}", config->sn, http_packet);
		return;
	}
	

 	int array_size = cJSON_GetArraySize(monitors);
	debug(LOG_DEBUG, "Array size of monitor is %d",array_size);
 	int i = 0;
 	cJSON *item;
 	for(i=0; i< array_size; i++) {
    	item = cJSON_GetArrayItem(monitors, i);
     	debug(LOG_DEBUG, "%s\n",item->valuestring);
		if(strcmp(item->valuestring , "wireless_traffic") == 0) {
			flag = 1;
			int wifi_index = 0;
			char interface_name[INTERFACELEN];
			char ssid[SSIDLEN];
			char assoc_num[4];
			cJSON_AddItemToObject(valueSetObj, "wireless_traffic", list = cJSON_CreateArray());
			while(read_ssid(wifi_index++, ssid, sizeof(ssid)/sizeof(ssid[0]))) {
				cJSON_AddItemToArray(list, package = cJSON_CreateObject());

				sprintf(tmp_value, "%d", wifi_index-1);
				cJSON_AddStringToObject(package,"radio_index",tmp_value);
				
				snprintf(interface_name, INTERFACELEN, "eth%d", wifi_index);
				
				read_counter(tmp_value, interface_name, "Rxbytes", sizeof(tmp_value)/sizeof(tmp_value[0]));
				cJSON_AddStringToObject(package,"Rxbytes", tmp_value);
			
				read_counter(tmp_value, interface_name, "Txbytes", sizeof(tmp_value)/sizeof(tmp_value[0]));
				cJSON_AddStringToObject(package,"Txbytes", tmp_value);
			
				read_counter(tmp_value, interface_name, "Rxpkt", sizeof(tmp_value)/sizeof(tmp_value[0]));
				cJSON_AddStringToObject(package,"Rxpkt", tmp_value);
			
				read_counter(tmp_value, interface_name, "Txpkt", sizeof(tmp_value)/sizeof(tmp_value[0]));
				cJSON_AddStringToObject(package,"Txpkt", tmp_value);

				read_assoc_client_count(interface_name, assoc_num, sizeof(assoc_num)/sizeof(assoc_num[0]));
				cJSON_AddStringToObject(package,"NumberOfAssociatedClients", assoc_num);

				
			}
		}
		else if(strcmp(item->valuestring , "wired_traffic") == 0) {
			flag = 1;
			cJSON_AddItemToObject(valueSetObj, "wired_traffic", package = cJSON_CreateObject());
			
			read_counter(tmp_value, "vlan2", "Rxbytes", sizeof(tmp_value)/sizeof(tmp_value[0]));
			cJSON_AddStringToObject(package,"Rxbytes", tmp_value);
			
			read_counter(tmp_value, "vlan2", "Txbytes", sizeof(tmp_value)/sizeof(tmp_value[0]));
			cJSON_AddStringToObject(package,"Txbytes", tmp_value);
			
			read_counter(tmp_value, "vlan2", "Rxpkt", sizeof(tmp_value)/sizeof(tmp_value[0]));
			cJSON_AddStringToObject(package,"Rxpkt", tmp_value);
			
			read_counter(tmp_value, "vlan2", "Txpkt", sizeof(tmp_value)/sizeof(tmp_value[0]));
			cJSON_AddStringToObject(package,"Txpkt", tmp_value);
			/*
			read_counter(tmp_value, "vlan2", "rx_errors", sizeof(tmp_value)/sizeof(tmp_value[0]));
			cJSON_AddStringToObject(package,"rx_errors", tmp_value);

			read_counter(tmp_value, "vlan2", "tx_errors", sizeof(tmp_value)/sizeof(tmp_value[0]));
			cJSON_AddStringToObject(package,"tx_errors", tmp_value);

			read_counter(tmp_value, "vlan2", "rx_discards", sizeof(tmp_value)/sizeof(tmp_value[0]));
			cJSON_AddStringToObject(package,"rx_discards", tmp_value);

			read_counter(tmp_value, "vlan2", "tx_discards", sizeof(tmp_value)/sizeof(tmp_value[0]));
			cJSON_AddStringToObject(package,"tx_discards", tmp_value);
			*/
		}
 	}
//.........这里部分代码省略.........
开发者ID:lonegoli,项目名称:R7000,代码行数:101,代码来源:cuci.c


示例18: CIwSVec2

该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ cJSON_GetArraySize函数代码示例发布时间:2022-05-30
下一篇:
C++ cJSON_Duplicate函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap