天天看點

cJSON解析null類型

int test(void)
{
	char str[] = "{\"test\":null}";
	printf("str:%s\n", str);
	
	cJSON *json = cJSON_Parse(str);
	if (json == NULL)
	{
		printf("json NULL\n");
		return -1;
	}

	cJSON *test =  cJSON_GetObjectItem(json, "test");
	if (test->type == cJSON_NULL) //判斷類型
	{
		printf("type : cJSON_NULL\n");
	}
	// printf("%d\n", test->valueint); //列印 0
	// printf("%s\n", test->valuestring); //段錯誤
	// printf("%ld\n", strlen(test->valuestring)); //段錯誤
}
           

繼續閱讀