How to use jsoncpp json to read and write C++ qt
This article will explain in detail how C++ qt uses jsoncpp json to read and write. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.
The use of JsonCpp
The project needs to use json under C++. I chose JsonCpp. The official website is: https://github.com/open-source-parsers/jsoncpp.
After decompression, use python to compile two h files and one cpp file:
(the computer needs to install python and install it on Baidu itself, so let's not talk about it here.)
After installing python, open the cmd window under windows and enter the jsoncpp folder as shown below:
Execute the command: python amalgamate.py will generate three json.h json-forwards.h jsoncpp.cpp files in the dist folder:
Add three files to the project and you can use them. I want qt to test and use them:
Main.cpp is as follows
# include # include # include "dist/json/json.h" using namespace std; int main (int argc, char * argv []) {/ / write Json::Value people1; people1 ["name"] = "Dione"; people1 ["sex"] = "male"; people1 ["age"] = 24; people1 ["note"] = "jsoncpp write test!"; Json::Value people2; people2 ["name"] = "Hulis"; people2 ["sex"] = "female" People2 ["age"] = 22; people2 ["note"] = "jsoncpp write test!"; Json::Value peoples; peoples.append (people1); peoples.append (people2); Json::Value writeValue; writeValue ["classname"] = "Class every three years"; writeValue ["peoples"] = peoples; Json::FastWriter fwriter; std::string strf = fwriter.write (writeValue); std::ofstream ofsf ("example_fast_writer.json") Ofsf