{"id":"System","contex":"HudThemeState","types":"Int","value":"2"} C++ 解析JSON
时间: 2023-12-30 18:03:13 浏览: 112
C++ 解析Json
以下是使用C++解析JSON的示例代码:
```cpp
#include <iostream>
#include <string>
#include <json/json.h>
int main() {
std::string jsonStr = R"({"id":"System","contex":"HudThemeState","types":"Int","value":"2"})";
Json::Value root;
Json::Reader reader;
bool parsingSuccessful = reader.parse(jsonStr, root);
if (!parsingSuccessful) {
std::cout << "Failed to parse JSON" << std::endl;
return 1;
}
std::string id = root["id"].asString();
std::string contex = root["contex"].asString();
std::string types = root["types"].asString();
int value = root["value"].asInt();
std::cout << "id: " << id << std::endl;
std::cout << "contex: " << contex << std::endl;
std::cout << "types: " << types << std::endl;
std::cout << "value: " << value << std::endl;
return 0;
}
```
阅读全文