jsoncpp

need some help in compiling a jsoncpp sample code

独自空忆成欢 提交于 2019-12-02 03:13:26
I am trying to compile a sample jsoncpp example, but there are tons of compiling errors showing up in "standard" headers. did any body see this any time ? [~]$ g++ -g -c json.cc -I/usr/local/include/json In file included from /usr/include/libio.h:62, from /usr/include/stdio.h:75, from /usr/lib/gcc/i686-redhat-linux/4.4.6/../../../../include/c++/4.4.6/cstdio:45, from json.cc:1: /usr/include/sys/cdefs.h:46:44: error: missing binary operator before token "(" /usr/include/sys/cdefs.h:50:44: error: missing binary operator before token "(" /usr/include/sys/cdefs.h:135:19: error: missing binary

How to get JsonCPP values as strings?

风格不统一 提交于 2019-12-01 21:00:49
问题 I am parsing json data using JsonCpp. I don't really need to understand the data, i just need to print out some properties and their values out. It somehow is hard to do. First I need to know what type the value is and then get the value and then convert it to string again! There is a styled writer but I don't want to use it as it appends some CRLF at the end. I do something like this CJsonHelper::getUInt(Json::Value &root, std::string key){ return root.get(key, 0-1).isInt() ? root.get(key, 0

How to get JsonCPP values as strings?

て烟熏妆下的殇ゞ 提交于 2019-12-01 19:35:19
I am parsing json data using JsonCpp . I don't really need to understand the data, i just need to print out some properties and their values out. It somehow is hard to do. First I need to know what type the value is and then get the value and then convert it to string again! There is a styled writer but I don't want to use it as it appends some CRLF at the end. I do something like this CJsonHelper::getUInt(Json::Value &root, std::string key){ return root.get(key, 0-1).isInt() ? root.get(key, 0-1).asUInt() : 0-1; } Could I just write a single function to get all the properties with just that

C++构造和解析JSON

守給你的承諾、 提交于 2019-12-01 12:51:41
JSON是一种轻量级的数据交互格式,易于人阅读和编写,同时也易于机器解析和生成,并有效地提升网络传输效率,实际项目中经常用到,相比xml有很多优点,问问度娘,优点一箩筐。 第三方库 json解析选用jsoncpp作为第三方库,jsoncpp使用广泛,c++开发首选。 jsoncpp目前已经托管到了github上,地址:https://github.com/open-source-parsers/jsoncpp 使用 使用c++进行构造json和解析json,选用vs2010作为IDE。工程中使用jsoncpp的源码进行编译,没有使用jsoncpp的库,为方便大家使用把dll和lib库也放到了我的工程jsoncpplib文件夹下,有需要的可以直接引用库。 待解析的json数据格式如下图: /******************************************************** Copyright (C), 2016-2017, FileName: main Author: woniu201 Email: wangpengfei.201@163.com Created: 2017/09/06 Description:use jsoncpp src , not use dll, but i also provide dll and lib. **********

Faster JsonCpp alternative that allows copying/mutability of Json objects?

独自空忆成欢 提交于 2019-12-01 08:54:57
问题 JsonCpp is slow. And the code is pretty messy. Is there any alternative that is faster, cleaner and supports stuff like: Json::Value val, copy; val["newMember"] = 100; val["newMember2"] = "hello"; copy = val; val["newMember2"] = "bye"; assert(val["newMember"] == copy["newMember"]); assert(val["newMember2"] != copy["newMember2"]); JsonCpp supports code like the one above. I've tried rapidjson , which is very fast, but unfortunately it does not support copying Json values. Any alternative?

Json-cpp - how to initialize from string and get string value?

不羁的心 提交于 2019-11-30 06:45:09
My code below crashes(Debug Error! R6010 abort() has been called). Can you help me? I'd also would like to know how to initialize the json object from a string value. Json::Value obj; obj["test"] = 5; obj["testsd"] = 655; string c = obj.asString(); Hello it is pretty simple: 1 - You need a CPP JSON value object (Json::Value) to store your data 2 - Use a Json Reader (Json::Reader) to read a JSON String and parse into a JSON Object 3 - Do your Stuff :) Here is a simple code to make those steps: #include <stdio.h> #include <jsoncpp/json/json.h> #include <jsoncpp/json/reader.h> #include <jsoncpp

Parsing JSON string with jsoncpp

烈酒焚心 提交于 2019-11-29 10:48:22
I'm trying to parse a JSON string encoded with PHP and sent over TCP to a C++ client. My JSON strings are like this: {"1":{"name":"MIKE","surname":"TAYLOR"},"2":{"name":"TOM","surname":"JERRY"}} On the C++ client I'm using the jsoncpp libraries: void decode() { string text = {"1":{"name":"MIKE","surname":"TAYLOR"},"2":{"name":"TOM","surname":"JERRY"}}; Json::Value root; Json::Reader reader; bool parsingSuccessful = reader.parse( text, root ); if ( !parsingSuccessful ) { cout << "Error parsing the string" << endl; } const Json::Value mynames = root["name"]; for ( int index = 0; index < mynames

[转] cmake源码编译安装jsoncpp

匆匆过客 提交于 2019-11-29 03:24:51
1、下载jsoncpp源码 wget https://github.com/open-source-parsers/jsoncpp/archive/master.zip 2、解压缩源码文件 unzip -x master.zip 3、cmake源码安装jsoncpp https://github.com/open-source-parsers/jsoncpp/wiki/Building cd jsoncpp-master mkdir -p ./build/debug cd ./build/debug cmake -DCMAKE_BUILD_TYPE=debug -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_INCLUDEDIR=include/jsoncpp -DARCHIVE_INSTALL_DIR=. -G "Unix Makefiles" ../.. sudo make && make install 安装时使用sudo仍然提示权限问题,最后直接切换root make && make install 安装成功 来源: https://www.cnblogs.com/lyggqm/p/11442926.html

Json-cpp - how to initialize from string and get string value?

对着背影说爱祢 提交于 2019-11-29 02:57:15
问题 My code below crashes(Debug Error! R6010 abort() has been called). Can you help me? I'd also would like to know how to initialize the json object from a string value. Json::Value obj; obj["test"] = 5; obj["testsd"] = 655; string c = obj.asString(); 回答1: Hello it is pretty simple: 1 - You need a CPP JSON value object (Json::Value) to store your data 2 - Use a Json Reader (Json::Reader) to read a JSON String and parse into a JSON Object 3 - Do your Stuff :) Here is a simple code to make those

Iterating through objects in JsonCpp

家住魔仙堡 提交于 2019-11-29 01:52:36
问题 I have a C++ application that uses jsoncpp to decode a JSON string. I have created the following function but it only shows me the top level objects... How do I get it to dump the entire object list? --Function-- SaveJSON( json_data ); bool CDriverConfigurator::PrintJSONTree( Json::Value & root, unsigned short depth /* = 0 */) { printf( " {type=[%d], size=%d} ", root.type(), root.size() ); if( root.size() > 0 ) { for( Json::ValueIterator itr = root.begin() ; itr != root.end() ; itr++ ) {