首页 > 技术文章 > cjson 使用方法

hshy 2020-05-10 22:28 原文

https://blog.csdn.net/lintax/article/details/51549345

int str_to_cJSON(char *json_string, char *str_val)
{
	char * out=NULL;
	cJSON *root=cJSON_CreateObject();
	if (!root)
	{
		printf("Error before: [%s]\n",cJSON_GetErrorPtr());
		return -1;
	}
	else
	{
		cJSON *item=cJSON_CreateString("Brett");
		cJSON_AddItemToObject(root,"firstName",item);
 
		out=cJSON_Print(root);
		printf("out2:%s\n",out);
 
		cJSON_Delete(root);
		if(out!=NULL)
		{
			free(out);
		}
	}
	return 0;
}

 

  

推荐阅读