我正在尝试在我的C++代码中实现jsoncpp库,我编写了一段简单的代码来试试它,它甚至都没有编译.
#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;
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
undefined reference to `Json::Reader::parse(std::string const&, Json::Value&, bool)'
undefined reference to `Json::Reader::Reader()'
undefined reference to `Json::Value::~Value()'
undefined reference to `Json::Value::Value(Json::ValueType)'
Run Code Online (Sandbox Code Playgroud)
我对C++有点新意,在include语句中有什么我想念的吗?或者jsonCpp需要额外的东西吗?
感谢您的时间!
我正在使用Jsoncpp来解析c ++的json格式.我不明白它是如何工作的; 开始时缺乏文档和示例,我想知道是否有人能给我一些快速指示.我发现的唯一例子涉及文件......
我正在使用HTTP堆栈在缓冲区中获取json消息.例如,缓冲区包含该消息{"state":"Running"}.我如何使用Json :: reader来解析它?我发现的唯一例子就是从文件中读取文件
你如何写一个Json消息的值?比如我想写"monkey : no"和"running : yes"成JSON的消息,我可以再在我的GET请求使用.
谢谢
更新:
1),例如,如何解析包含json消息的缓冲区,如下所示:
char* buff;
uint32_t buff_size;
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 jsoncpp(最新版本)的合并版本,但它产生了未解决的外部符号链接错误。我使用的代码是
#include <json/json.h>
int main(){
Json::Value root;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
它给了我错误
1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall Json::Value::~Value(void)" (??1Value@Json@@QAE@XZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall Json::Value::Value(enum Json::ValueType)" (??0Value@Json@@QAE@W4ValueType@1@@Z) referenced in function _main
Run Code Online (Sandbox Code Playgroud) 我必须将我的应用程序所做的事情记录到一个 json 文件中。预计应用程序会持续数周,所以我想增量地编写 json 文件。
目前我正在手动编写 json,但是有一些日志阅读器应用程序正在使用 Jsoncpp lib,也应该用 Jsoncpp lib 写日志。
但是在手册和一些例子中我没有发现任何类似的东西..它总是像:
Json::Value root;
// fill the json
ofstream mFile;
mFile.open(filename.c_str(), ios::trunc);
mFile << json_string;
mFile.close();
Run Code Online (Sandbox Code Playgroud)
那不是我想要的,因为它不必要地填满了内存。我想循序渐进地做..一些建议?
嗨,我想用lib jsoncpp做一些简单的事情:
std::map<int,string> mymap;
mymap[0]="zero";
mymap[1]= "one";
Json::Value root;
root["teststring"] = "m_TestString"; //it works
root["testMap"] = mymap; //it does not work
Json::StyledWriter writer;
string output = writer.write( root );
Run Code Online (Sandbox Code Playgroud)
错误是:错误C2679:二进制'=':找不到运算符,它采用类型'std :: map <_Kty,_Ty>'的右手操作数
你有想法解决这个问题吗?我明白json :: value不能接受一个map但是要创建一个json文件,对吧?非常感谢你
所以我一直在互联网上寻找使用libcurl和jsoncpp解析JSON的基本示例,但我找不到一个.
有人可以指出我正确的方向或指定这里,一个使用libcurl和jsoncpp的简单例子,从指定的网页下载json(链接本身以.json结尾所以它将直接拉json)解析并打印它.
所有帮助表示赞赏.谢谢!
Euden
我的主要需求是如何在顶级数据中找到元素的数量。
鉴于json数据:
{
[
{Key11:Value11,Key12:Value12,...Key1N:Value1N},
{Key21:Value21,Key22:Value22,...Key2N:Value2n},
{Key31:Value31,Key32:Value32,...Key3N:Value3N},
{Key41:Value41,Key42:Value42,...Key4N:Value4N},
.
.
.
KeyZ1:ValueZ1,KeyZ2:ValueZ2,...KeyZN:ValueZN}
]
}
Run Code Online (Sandbox Code Playgroud)
如何在 Json 数据中找到数组元素的数量?
此外,鉴于杰森数据:
{
{Key11:Value11,Key12:Value12,...Key1N:Value1N}
}
Run Code Online (Sandbox Code Playgroud)
如何在 json 数据中找到键值元素的数量?
我是 cmake 的新手。它工作得很好,但现在我遇到一些链接错误:
undefined reference to `Json::Reader::Reader()'
undefined reference to `Json::Value::Value(Json::ValueType)'
undefined reference to `Json::Reader::parse(std::basic_istream<char, std::char_traits<char> >&, Json::Value&, bool)'
undefined reference to `google::protobuf::MessageLite::ParseFromArray(void const*, int)'
Run Code Online (Sandbox Code Playgroud)
还有更多这样的类型。
我想我必须在某个地方添加 jsoncpp 库。
这里有人知道如何做到这一点吗?
我有一个接收 aJson::Value作为参数的外部库。然后它会输出一个包含 JSON 结构的字符串,我Json::Value在该结构中的某处传递。
我正在尝试使用JsonCpp{}在其中放置一个空对象。Json::Value
最终,我试图从std::string包含"{}"的Json::Value.
当我声明 aJson::Value并且什么都不做并将它传递给我的图书馆时,我得到NULL而不是{}......
我有一个JSON对象数组,jsonArr说,有以下几种:
[
{ "attr1" : "somevalue",
"attr2" : "someothervalue"
},
{ "attr1" : "yetanothervalue",
"attr2" : "andsoon"
},
...
]
Run Code Online (Sandbox Code Playgroud)
使用jsoncpp,我试图遍历数组并检查每个对象是否有成员"attr1",在这种情况下我想将相应的值存储在向量中values.
我尝试过类似的东西
Json::Value root;
Json::Reader reader;
Json::FastWriter fastWriter;
reader.parse(jsonArr, root);
std::vector<std::string> values;
for (Json::Value::iterator it=root.begin(); it!=root.end(); ++it) {
if (it->isMember(std::string("attr1"))) {
values.push_back(fastWriter.write((*it)["uuid"]));
}
}
Run Code Online (Sandbox Code Playgroud)
但不断收到错误消息
libc++abi.dylib: terminating with uncaught exception of type Json::LogicError: in Json::Value::find(key, end, found): requires objectValue or nullValue
Run Code Online (Sandbox Code Playgroud)