In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces JsonCpp how to achieve data reading, the article is very detailed, has a certain reference value, interested friends must read it!
Jsoncpp is a cross-platform open source library for C++. Download address: http://sourceforge.net/projects/jsoncpp/. Assert as an error handling method, will stop the running of the program, remember!
1) parsing json information from a file
Std::ifstream ifs
Ifs.open ("testdata.json", std::ios::binary)
Json::Reader reader (Json::Features::strictMode ())
Json::Value root
If (NULL = = reader.parse (ifs, root))
{
Ifs.close ()
Return
}
Ifs.close ()
2) parsing json information from cache
Std::string strJsonText = "{\" total\ ": 1,\" toReturn\ ": [{\" createTime\ ":\" 200808061145260000800\ ",\" createUser\ ":\" Zhang San\ "}],\" success\ ": false}"
Json::Reader reader (Json::Features::strictMode ())
Json::Value root
If (NULL = = reader.parse (istrJsonText, root)) return
Note:
1)
When JsonCpp parses illegal json, it will actively tolerate fault into character types, and when the character type is subscript, the assert termination program will be triggered. Solution: enable strict mode, return false when parsing illegal json, and no longer automatically tolerate faults. When creating a read object, specify the property: Json::Reader reader (Json::Features::strictMode ())
Use of Json::Reader reader is not recommended
2) if the text file in Json format is opened with Windows notepad, the BOM logo may be added to the text, resulting in reading failure. It is recommended to use Notepad++ to modify and view it.
The above is all the contents of the article "how to achieve data reading in JsonCpp". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 279
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
The type PipeWriter copy code is as follows:
© 2024 shulou.com SLNews company. All rights reserved.