json官网: https://www.json.org/

cJSON代码地址: https://github.com/DaveGamble/cJSON

esp8266因为使用了自己的函数,所以上面的json库要移植一下才能使用。

下面是csdn某博主移植好的cJSON库文件:

备注:移植教程 https://blog.csdn.net/yannanxiu/article/details/52713746

//json*****************************************
void ICACHE_FLASH_ATTR mycjson(void)
{

	cJSON *pRoot = cJSON_CreateObject();
	cJSON *pValue = cJSON_CreateObject();

	//新增一个字段mac到根点,数值是tempMessage
	cJSON_AddStringToObject(pRoot,"mac","lllbbb");
	//新增一个字段number到根点,数值是2
	cJSON_AddNumberToObject(pRoot,"number",2);

	cJSON_AddStringToObject(pValue,"mac","xuhongv");
	cJSON_AddNumberToObject(pValue,"age",18);
	cJSON_AddStringToObject(pValue,"mac","https://blog.csdn.net/xh870189248");

	cJSON_AddItemToObject(pRoot, "value",pValue);

	//数组初始化
	int hex[5]={51,15,63,22,96};
	cJSON *pHex = cJSON_CreateIntArray(hex,5);
	cJSON_AddItemToObject(pRoot,"hex",pHex);

	char *s = cJSON_Print(pRoot);
	os_printf("\r\n creatJson : %s\r\n", s);

	//释放内存
	cJSON_free((void *) s);
	cJSON_Delete(pRoot);

}
//json end*****************************************



//主函数调用
mycjson();