例如 0b 13 b3 95 48 9d 3e 63 9c c4 70 f4 50 85 55 5e 数据
start cmd[ 27 01 f7 02 10 0b 13 b3 95 48 9d 3e 63 9c c4 70 f4 50 85 55 5e 01 01 50 FB ]
set_potk json 数据10进制 VALUE 11,19,179,149,72,157,62,99,156,196,112,244,80,133,85,94
- {“jsonrpc”:“2.0”,“type”:2,“id”:0,“method”:“method”,“message”:{“VALUE”:[11,19,179,149,72,157,62,99,156,196,112,244,80,133,85,94]},“N”:0,“query”:“”,“uri”:"f}
{“id”:0,“jsonrpc”:“2.0”,“result”:{“SUCCESS”:0},“uri”:“factory_cmd/sys/key/potk”}
CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name)
{
cJSON *array = cJSON_CreateArray();
if (add_item_to_object(object, name, array, &global_hooks, false))
{
return array;
}
cJSON_Delete(array);
return NULL;
}
CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject_1(cJSON * const object, const char * const name, cJSON *array)
{
//cJSON *array = cJSON_CreateArray();
if (add_item_to_object(object, name, array, &global_hooks, false))
{
return array;
}
cJSON_Delete(array);
return NULL;
}
将数组转长json 数据格式
int set_potkcheck(unsigned char data[],int len)
{
int r=0,i;
std::string ret;
std::string str;
char buf[64];
cJSON *setjson = cJSON_Parse(k_app_setpotkcheck);
cJSON *message = cJSON_GetObjectItem(setjson, "message");
cJSON *VALUE = cJSON_GetObjectItem(setjson, "VALUE");
cJSON_DeleteItemFromObject(message, "VALUE");
cJSON *json_array = cJSON_CreateArray();
for (int i = 0; i < len; ++i) {
cJSON_AddItemToArray(json_array, cJSON_CreateNumber(data[i])); // 转成10进制数值
}
cJSON_AddArrayToObject_1(message, "VALUE",json_array);
char *modified_json = cJSON_PrintUnformatted(setjson);
std::string s2=modified_json;
if (0 == s_factoryCmd.set(modified_json, ret)) {
printf("%s\n", __func__);
printf(" - %s\n", modified_json);
printf(" - %s\n", ret.c_str());
DEBUG_PRINTF("%s\n", __func__);
DEBUG_PRINTF(" - %s\n", modified_json);
DEBUG_PRINTF(" - %s\n", ret.c_str());
cJSON *json = cJSON_Parse(ret.c_str());
cJSON *result = cJSON_GetObjectItem(json, "result");
cJSON *SUCCESS = cJSON_GetObjectItem(result, "SUCCESS");
if (cJSON_IsNumber(SUCCESS)) {
printf("SUCCESS: %d\n", SUCCESS->valueint);
}
cJSON_Delete(json);
return SUCCESS->valueint;
}
return 1;
}