json总结

一、生成json结构体: 
{
        "function":     [             // pJsonDetail = cJSON_CreateArray();cJSON_AddItemToObject(pstJsonhead, "function", pJsonDetail);
       {  
//pJsonDstDetail = cJSON_CreateObject(); cJSON_AddItemReferenceToArray(pJsonDetail, pJsonDstDetail);  
                        "name": "4GDayConsumeFlow",
                        "code": 1798,
                        "count":        343,
                        "date": 127
                }
   ],
        "iccid":        "89860617030077961780",
        "uuid": "4DC96C04A542E69914A50607B6CEE9660E9403BCEDF6C375932CE8A16AE68A65127366F54A3AAAE96D6A5B4CA3984233"
}

UINT32 LastFlowInfoToJson(cJSON * pstJsonhead,CHAR * pszSimICCID,UINT64 ulLastTime,DOUBLE slDurationFlow,CHAR * g_szUuid)
{

cJSON *pJsonDstDetail = NULL;
cJSON *pJsonDetail  = NULL;
pJsonDetail = cJSON_CreateArray();
if (pJsonDetail == NULL)
{
       WEB_ErrorTRACE(("cJSON_CreateObject Error\n"));
       print_info("cJSON_CreateObject Error\n");
       return VOS_ERR;
}
        
cJSON_AddItemToObject(pstJsonhead, "function", pJsonDetail);
        
pJsonDstDetail = cJSON_CreateObject();
if(!pJsonDstDetail)
{
print_info(" cJSON_Parse error: %s\n", cJSON_GetErrorPtr());
return VOS_ERROR;
}
       cJSON_AddStringToObject(pJsonDstDetail, "name","4GDayConsumeFlow" );
       cJSON_AddNumberToObject(pJsonDstDetail, "code", 0x706);
       cJSON_AddNumberToObject(pJsonDstDetail, "count", slDurationFlow);
       cJSON_AddNumberToObject(pJsonDstDetail, "date", ulLastTime);
       
       
    
cJSON_AddItemReferenceToArray(pJsonDetail, pJsonDstDetail);
    
cJSON_AddStringToObject(pstJsonhead, "iccid", pszSimICCID);
cJSON_AddStringToObject(pstJsonhead,"uuid", g_szUuid);
}

pJsonMsg =cJSON_Print(pstJsonhead);

cJSON_Delete(pstJsonhead);    //pJsonDstDetail ,pJsonDetail不需要单独释放

free(4GDayConsumeFlow);    //仅仅拷贝一份,所以需要单独释放

free(pszSimICCID);

free(g_szUuid);

          

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值