char buff[1024]= {0};
char* rep;
int rep_len;
int len,i;
cJSON *jsonpack = cJSON_CreateObject();
cJSON *arraypack = cJSON_CreateArray();
cJSON *datapack = cJSON_CreateObject();
if(datapack == NULL)
{
if(datapack)
{
cJSON_Delete(datapack);
}
if(arraypack)
{
cJSON_Delete(arraypack);
}
if(jsonpack)
{
cJSON_Delete(jsonpack);
}
return;
}
if(arraypack == NULL)
{
delay_ms(1);
if(datapack)
{
cJSON_Delete(datapack);
}
if(arraypack)
{
cJSON_Delete(arraypack);
}
if(jsonpack)
{
cJSON_Delete(jsonpack);
}
return;
}
if(jsonpack == NULL)
{
if(datapack)
{
cJSON_Delete(datapack);
}
if(arraypack)
{
cJSON_Delete(arraypack);
}
if(jsonpack)
{
cJSON_Delete(jsonpack);
}
delay_ms(1);
return;
}
cJSON_AddStringToObject(datapack, "name", "IceA");
cJSON_AddStringToObject(datapack, "m_id","123456");
cJSON_AddStringToObject(datapack, "a_id", "");
cJSON_AddNumberToObject(datapack, "price", 5);
cJSON_AddNumberToObject(datapack, "num", 2);
cJSON_AddNumberToObject(datapack, "subtotal", 10);
cJSON_AddItemToArray(arraypack, datapack);
cJSON_AddStringToObject(jsonpack, "id", "20200907090000000001");
cJSON_AddStringToObject(jsonpack, "dev","34EAE7086A98");
cJSON_AddStringToObject(jsonpack, "sec", temp3);
cJSON_AddStringToObject(jsonpack, "state", "cancel");
cJSON_AddStringToObject(jsonpack, "type", "0");
cJSON_AddNumberToObject(jsonpack, "total", 10);
cJSON_AddItemToObject(jsonpack, "data", arraypack);
rep = cJSON_Print(jsonpack);
rep_len = strlen(rep);
uart2_sendstring(rep,rep_len);
if(datapack)
{
cJSON_Delete(datapack);
}
if(arraypack)
{
cJSON_Delete(arraypack);
}
if(jsonpack)
{
cJSON_Delete(jsonpack);
}
if(rep)
{
free(rep);
//rep = NULL;
}
|