jsoncpp

Problems including jsonCpp headers

别来无恙 提交于 2019-12-04 13:02:30
I'm trying to implement the jsoncpp libraries in my C++ code, I wrote a simple piece of code just to try it out, and it's not even compiling. #include <stdio.h> #include <stdlib.h> #include <stddef.h> #include <string.h> #ifndef json_included #define json_included #include "jsoncpp\include\json\json.h" #endif //#include "json\jsonC\json.h" int main(int argc, char **argv) { std::string example = "{\"array\":[\"item1\", \"item2\"], \"not an array\":\"asdf\"}"; Json::Value value; Json::Reader reader; bool parsed = reader.parse(example, value, false); std::cout << parsed; return 0; } The errors i

JsonCpp - when having a json::Value object, how can i know it's key name?

别等时光非礼了梦想. 提交于 2019-12-04 05:34:23
Let suppose I have this Json file: [ { "id": 0 } ] using jsoncpp, i can have a Json::Value object by doing this: Json::Value node = root[0u]["id"]; OK, somewhere else in the code, I'm getting that node object, and I want to get some info out of it. I can get its value, like this: int node_value = node.asInt(); But how can I get its NAME? (i.e the "id"). It should be something like: string node_name = node.Name(); //or maybe: string node_name2 = node.Key(); but I can't find anything similar. Help? How can I get a node's name? You can use Json::Value::getMemberNames() to iterate through the

jsoncpp. find object in array by matching value

谁都会走 提交于 2019-12-04 05:05:46
I have this JSON object: {"books":[ { "author" : "Petr", "book_name" : "Test1", "pages" : 200, "year" : 2002 }, { "author" : "Petr", "book_name" : "Test2", "pages" : 0, "year" : 0 }, { "author" : "STO", "book_name" : "Rocks", "pages" : 100, "year" : 2002 } ] } For example, I need to find a book(s) which author key is equal to Petr . How can I do this? Right now I have this piece of code: Json::Value findBook(){ Json::Value root = getRoot(); cout<<root["books"].toStyledString()<<endl; //Prints JSON array of books mentioned above string searchKey; cout<<"Enter search key: "; cin>>searchKey;

C++ JsonCPP - Removing objectValue from an arrayValue

烂漫一生 提交于 2019-12-03 12:40:40
问题 I've only been using the jsonCPP lib for a couple of month now. Im trying to add and remove an object in an array. Ive used a number of different JSON libs on different platforms but I'm finding it very difficult to work with JsonCPP. Here is the Json: { "type": "Disc", "media": "DVD", "adapter": "DVDCodecs", "transportControls" : [ {"Action":"Left", "ActionCode" : "1a"}, {"Action":"Right", "ActionCode" : "2a"}, {"Action":"Up", "ActionCode" : "1b"}, {"Action":"Down", "ActionCode" : "4c"}, {

how to writing a cmake Module for jsoncpp?

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to use jsoncpp for writing a C++ code in order to parse a JSON file. Let me explain what I did. I created a CMakeLists.txt and I made a FindJsoncpp.cmake along with a simple c++ file to test jsoncpp . When I compile the C++ source without cmake using -I/usr/include/jsoncpp/ -ljsoncpp it works fine. but when I try to build it using cmake it cannot find json.h header file that I included in my c++ source code. here is my CMakeLists.txt : cmake_minimum_required (VERSION 2.6) project (Parser) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "$

C++ JsonCPP - Removing objectValue from an arrayValue

三世轮回 提交于 2019-12-03 03:06:15
I've only been using the jsonCPP lib for a couple of month now. Im trying to add and remove an object in an array. Ive used a number of different JSON libs on different platforms but I'm finding it very difficult to work with JsonCPP. Here is the Json: { "type": "Disc", "media": "DVD", "adapter": "DVDCodecs", "transportControls" : [ {"Action":"Left", "ActionCode" : "1a"}, {"Action":"Right", "ActionCode" : "2a"}, {"Action":"Up", "ActionCode" : "1b"}, {"Action":"Down", "ActionCode" : "4c"}, {"Action":"Center", "ActionCode" : "5e"}, {"Action":"OK", "ActionCode" : "5a"}, {"Action":"SubTitles",

Jsoncpp writing float values incorrectly

匿名 (未验证) 提交于 2019-12-03 01:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am reading from a JSON file using jsoncpp. When I write back to the file, my float values are slightly off. For the sake of testing, I decided to parse the file to a Json::Value and then write that value back to the file. I would expect it to look the same, but instead the float values are different. Example: "Parameters": { "MinXValue": 0.1, "MaxXValue": 0.15, "MinYValue": 0.25, "MaxYValue": 1.1, "MinObjectSizeValue": 1 } writes as: "Parameters": { "MinXValue": 0.10000000000000001, "MaxXValue": 0.14999999999999999, "MinYValue": 0.25,

[C++] JsonCPP 的使用 完整配置过程

匿名 (未验证) 提交于 2019-12-03 00:09:02
最近准备开发一个程序 需要用到C++ 解析json 原始的C++解析json是不现实的 自己也写不出来json解析方法(主要是不靠谱) 所以找到了jsoncpp 这个库 但是。。。 因为各种原因 配置的让我想哭 接下来我来分享一下 我配置这个库的过程吧 首先发现了这个博文(感谢) https://www.cnblogs.com/esCharacter/p/7657676.html#commentform 从这个博文中找到了json的项目地址 然后下载了下来 https://github.com/open-source-parsers/jsoncpp 得到了这样的目录 接着,按照博文说的开始构建 dist... 这里需要安装python 我的电脑已经安装好了 直接运行那个命令 python amalgamate . py    发现会失败...   会提示找不到一个文件...   去看了github上面的iss 然后知道需要先cmake 一下   但是那个提出解决方案的人是ubuntu 的操作系统 在windows下默认是没有cmake的   我就想到了我的vs2019似乎是有这个文件的 在 vs的安装目录下直接搜索 cmake.exe 然后找到了 打开这个文件所在位置    cmd 切换目录到 jsoncpp源码根目录 拖动cmake.exe 到cmd窗口 输入一个空格

JSONCPP Writing to files

﹥>﹥吖頭↗ 提交于 2019-12-02 18:08:08
JSONCPP has a writer, but all it seems to do is get info from the parser and then output it into a string or a stream. How do I make it alter or create new objects, arrays, values, strings, et cetera and write them into the file? #include<json/writer.h> Code: Json::Value event; Json::Value vec(Json::arrayValue); vec.append(Json::Value(1)); vec.append(Json::Value(2)); vec.append(Json::Value(3)); event["competitors"]["home"]["name"] = "Liverpool"; event["competitors"]["away"]["code"] = 89223; event["competitors"]["away"]["name"] = "Aston Villa"; event["competitors"]["away"]["code"]=vec; std:

need some help in compiling a jsoncpp sample code

自古美人都是妖i 提交于 2019-12-02 14:06:49
问题 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