#include "math.h" #include#include #include #include #include #include static int get_json_int_para( int *pValue_set, cJSON *pObject, const char *pStringNeedToFind ) { cJSON * pItem = cJSON_GetObjectItem ( pObject, pStringNeedToFind ) ; if ( NULL != pItem ) { cJSON * pItem_value = cJSON_GetObjectItem ( pItem, "value" ) ; if ( NULL != pItem_value ) { *pValue_set = pItem_value->valueint ; #if PRINTF_ALL_PARA printf ( "%s=%dn", pStringNeedToFind, *pValue_set ); #endif } else { printf("(get_json_int_para)no %sn", pStringNeedToFind); return -1 ; } } else { printf("(get_json_int_para)no %sn", pStringNeedToFind); return -1 ; } return 0; } static int get_json_str_para( char *pValue_set, cJSON *pObject, const char *pStringNeedToFind ) { int iValueLen; cJSON * pItem = cJSON_GetObjectItem ( pObject, pStringNeedToFind ) ; if ( NULL != pItem ) { cJSON * pItem_value = cJSON_GetObjectItem ( pItem, "value" ) ; if ( NULL != pItem_value ) { iValueLen = strlen( pItem_value->valuestring ); strncpy( pValue_set, pItem_value->valuestring, iValueLen ) ; #if PRINTF_ALL_PARA printf ( "%s=%sn", pStringNeedToFind, pValue_set ); #endif } else { printf("(get_json_str_para)no %sn", pStringNeedToFind); return -1 ; } } else { printf("(get_json_str_para)no %sn", pStringNeedToFind); return -1 ; } return 0; } int cjson_read_udp_para ( char *pMenu, struct UDP_PARA *udp_para ) { struct UDP_PARA *pT_udp_para = (struct UDP_PARA *)udp_para; FILE *pFp = NULL; cJSON *pJson; char *pOut; int iLen; int iCnt; char* pData; int iRetAccess; udp_para_init(pT_udp_para);//初始化所有参数 //iRetAccess = access ( WIFI_PARA_MENU , F_OK ) ; iRetAccess = access ( pMenu, F_OK ) ; printf ( "(cjson_read_udp_para)menu=%sn",pMenu ); if ( -1 == iRetAccess ) { printf ( "(cjson_read_udp_para)can not find the menu:%s nn", pMenu ); iRetAccess = access ( WIFI_PARA_MENU, F_OK ) ; if ( -1 == iRetAccess ) { printf ( "(cjson_read_udp_para)can not find the local cjson_read_udp_para menu:%s nn", WIFI_PARA_MENU ); return -1; } else { pFp = fopen ( WIFI_PARA_MENU, "r" ); //as4_comm_result->_file_menu.process_menu } } else { pFp = fopen ( pMenu, "r" ); } if( NULL == ( pFp ) ) { return -1; } fseek ( pFp, 0, SEEK_END ); iLen = ftell( pFp ); fseek( pFp, 0, SEEK_SET ); pData = ( char*)malloc( iLen + 1 ); fread( pData, 1, iLen, pFp ) ; fclose( pFp ); if ( NULL != ( pFp ) ) { //PX("data=%sn",data ); pJson=cJSON_Parse ( pData ); //获取整个大的句柄 if ( ( NULL != pJson ) && ( pJson->type == cJSON_Object ) ) { pOut = cJSON_Print ( pJson ); //这个是可以输出的。为获取的整个json的值 #if PRINTF_ALL_PARA printf ( "(cjson_read_udp_para)json pack into cjson success!!! n" ); 一串数字也会被解析为json格式 #endif } else { printf ( "(cjson_read_udp_para)json pack into cjson error n" ); return -2; } cJSON * item_remote_ip = cJSON_GetObjectItem ( item_socket_set, "remote_ip" ) ; if ( NULL != item_remote_ip ) { strncpy( pT_udp_para->socket_set.cRemoteIP, item_remote_ip->valuestring, strlen( item_remote_ip->valuestring ) ) ; #if 1 printf ( "RemoteIP=%sn", pT_udp_para->socket_set.cRemoteIP ); #endif } else { printf("(cjson_read_udp_para)no cRemoteIPn"); } } else { printf("(cjson_read_udp_para)no local_portn"); } cJSON * pUDP_para = cJSON_GetObjectItem ( pJson, "udp_para" ) ; if ( NULL != pUDP_para ) { get_json_int_para( (int *)&pT_udp_para->HT_TxStream.iValue_set, pUDP_para, "nvram_set_HT_TxStream" ); get_json_int_para( (int *)&pT_udp_para->HT_RxStream.iValue_set, pUDP_para, "nvram_set_HT_RxStream" ); get_json_int_para( (int *)&pT_udp_para->WlanSiteSurvey.iValue_set, pUDP_para, "nvram_set_WlanSiteSurvey" ); get_json_str_para( pT_udp_para->GatewayWanSet_tmp.cValue_set_ip, pUDP_para, "nvram_set_GatewayWanSet_tmp_ip" ); } else { printf("(cjson_read_udp_para)no cur file n"); } } cJSON_Delete ( pJson ); free ( pData ); return 0; }



