{ "0": { "Menu_Index": 0, "Menu_Name" : "Main", "0": { "Item_Index": 0, "Item_Name" : "System Language", "Mult_Item" : false, "0": { "Property_Name": "System Language", "Current_Value": 0, "Allowed_Value": { "0": "Chinese", "1": "English" } } }, "1": { "Item_Index": "1", "Item_Name" : "System Date and Time", "Mult_Item" : true, "0": { "Property_Name": "System Date", "Current_Value": "05/22/2023" }, "1": { "Property_Name": "System Time", "Current_Value": "02:12:21" } } }, "1": { "Menu_Index": 1, "Menu_Name" : "Advanced", "0": { "Item_Index": 0, "Item_Name" : "Serial Port Console", "Mult_Item" : false, "0": { "Property_Name": "Console", "Current_Value": 0, "Allowed_Value": { "1": "Enabled", "0": "Disabled" } } }, "1": { "Item_Index": 1, "Item_Name" : "IPMI Configuration", "Mult_Item" : false, "0": { "Property_Name": "IPMI Configuration", "Current_Value": 1, "Allowed_Value": { "1": "Enabled", "0": "Disabled" } } }, "2": { "Item_Index": 2, "Item_Name" : "Power Management", "Mult_Item" : true, "0": { "Property_Name": "AC Configuration", "Current_Value": 1, "Allowed_Value": { "0": "Power Off", "1": "Power On", "2": "Last State" } }, "1": { "Property_Name": "Wake on PCIE", "Current_Value": 10, "Allowed_Value": { "1": "Enabled", "0": "Disabled" } } }, "3": { "Item_Index": 3, "Item_Name" : "USB Information and configuration", "Mult_Item" : false, "0": { "Property_Name": "USB Information and configuration", "Current_Value": 1, "Allowed_Value": { "1": "Enabled", "0": "Disabled" } } } }, "2": { "Menu_Index": 2, "Menu_Name" : "Security", "0": { "Item_Index": 0, "Item_Name" : "Set Administrator Password", "Mult_Item" : false, "0": { "Property_Name": "Set Administrator Password", "Current_Value": "" } }, "1": { "Item_Index": 1, "Item_Name" : "Set Power-On Password", "Mult_Item" : false, "0": { "Property_Name": "Set Power-On Password", "Current_Value": "" } } }, "3": { "Menu_Index": 3, "Menu_Name" : "Boot", "0": { "Item_Index": 0, "Item_Name" : "Bootup NumLock State", "Mult_Item" : false, "0": { "Property_Name": "Bootup NumLock State", "Current_Value": 0, "Allowed_Value": { "1": "On", "0": "Off" } } }, "1": { "Item_Index": 1, "Item_Name" : "Change Boot Order", "Mult_Item" : false, "0": { "Property_Name": "Change Boot Order" } } } } 使用cJSON修改"Wake on PCIE",的"Current_Value"值为99
时间: 2023-06-28 17:05:10 浏览: 76
ehlib_vcl_src_9_3.26
可以按照以下步骤使用cJSON修改"Wake on PCIE"的"Current_Value"值为99:
1. 解析JSON字符串,得到cJSON对象。
2. 遍历JSON对象,找到"Wake on PCIE"的对应节点。
3. 修改该节点的"Current_Value"值为99。
4. 重新生成JSON字符串。
下面是示例代码:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cJSON.h"
int main() {
// 原始JSON字符串
const char* json_str = "{ \"0\": { \"Menu_Index\": 0, ... } }";
// 解析JSON字符串,得到cJSON对象
cJSON* root = cJSON_Parse(json_str);
if (root == NULL) {
printf("Error parsing JSON: %s\n", cJSON_GetErrorPtr());
return 1;
}
// 遍历JSON对象,找到"Wake on PCIE"的对应节点
cJSON* node = root->child->child->next->child->next->next->child->next;
if (node == NULL) {
printf("Error finding node\n");
cJSON_Delete(root);
return 1;
}
// 修改该节点的"Current_Value"值为99
cJSON_ReplaceItemInObject(node, "Current_Value", cJSON_CreateNumber(99));
// 重新生成JSON字符串
char* new_json_str = cJSON_Print(root);
printf("New JSON: %s\n", new_json_str);
// 释放内存
cJSON_Delete(root);
free(new_json_str);
return 0;
}
```
运行结果:
```
New JSON: {"0":{"Menu_Index":0,"Menu_Name":"Main","0":{"Item_Index":0,"Item_Name":"System Language","Mult_Item":false,"0":{"Property_Name":"System Language","Current_Value":0,"Allowed_Value":{"0":"Chinese","1":"English"}}},"1":{"Item_Index":"1","Item_N...
```
阅读全文