Jsoncpp Usage Details and link problem solving, jsoncpp Usage Details
JSON (JavaScript Object Notation) is a lightweight data exchange format. Easy to read and write. It is also easy to parse and generate machines. It is based on a subset of JavaScript Programming Language, Standard ECMA-262 3rd Edition-December 1999. JSON uses a completely language-independent text format, but it also uses a habit similar to the C language family (including C, C ++, C #, Java, JavaScript, Perl, Python, and so on ). These features make JSON an ideal data exchange language.
JSON is constructed in two structures:
A collection of name/value pairs ). In different languages, it is understood as an object, record, struct, dictionary, and hash table ), keyed list or associative array ).
An ordered list of values ). In most languages, it is understood as an array ).
These are common data structures. In fact, most modern computer languages support them in some form. This makes it possible to exchange a data format between programming languages that are also based on these structures.
To use JsonCpp, follow these steps:
1. Download JsonCpp
You can download from my resources or from the official website.
Ii. Compile Lib
Home VS open the \ jsoncpp-src-0.5.0 \ jsoncpp-src-0.5.0 \ makefiles \ vs71 directory of the project file, and then compile it to generate the relevant Lib Library (default generation: json_vc71_libmt.lib)
3. Create another project, add the json_vc71_libmt.lib Library to the relevant path, and set the corresponding project properties. The source code is as follows:
// Testjson
ifstream ifs; ifs.open("testjson.json"); assert(ifs.is_open()); Json::Reader reader; Json::Value root; if ((!reader.parse(ifs, root, false))) { return false; } std::string name = root["name"].asString(); int age = root["age"].asInt();
Link Library and add header file:
#pragma comment(lib, "json_vc71_libmt.lib")#include "../jsoncpp/include/json.h"#include<fstream>#include <cassert>using namespace std;
Note that the following errors may occur when running the new project:
Problem 1: error LINK2038: the "RuntimeLibrary" mismatch is detected.
Solution: set the project compilation option of the new project to the same as that of the jsoncpp project:
Question 2: json_value.asm: No such file or directory
Solution: Set the return program output in the compilation option of the jsoncpp project to no list:
Refer to blog:
Jsoncpp usage explanation and link Solution
C ++ parses Json -- jsoncpp
Use of Jsoncpp
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.