函数:

cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem);

参数:

array 插入的json项

which 插入第几项

newitem 插入项

代码示例:

	/* 创建object对象 */
	cJSON *pstJsonObject;
	pstJsonObject = cJSON_CreateObject();

	/* 创建键值 以及数字 */
	cJSON *pstJsonItem;
	pstJsonItem = cJSON_CreateNumber();

	/* 错误设置key 方法
	pstJsonItem->string = "key";
	*/
	char key[] = "key";
	memcpy(pstJsonItem->string, key, sizeof(key);

	/* 插入位置1 插入对象pstJsonObject  插入项pstJsonItem*/
	cJSON_InsertItemInArray(pstJsonObject, 1, pstJsonItem);

GitHub 加速计划 / cj / cJSON
10.44 K
3.16 K
下载
Ultralightweight JSON parser in ANSI C
最近提交(Master分支:1 个月前 )
424ce4ce This reverts commit 5b502cdbfb21fbe5f6cf9ffbd2b96e4281a741e6. Related to #860 2 个月前
32497300 - 4 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐