При попытке парсинга вылетают ошибки, формат json:
{"edges":[{"src":"name0","dest":"name1","delay":"5"},{"src":"name2","dest":"name0","delay":"6"},{"src":"name0","dest":"name4","delay":"6"},{"src":"name2","dest":"name3","delay":"8"},{"src":"name1","dest":"name5","delay":"7"},{"src":"name1","dest":"name5","delay":"7"},{"src":"name2","dest":"name4","delay":"4"},{"src":"name2","dest":"name4","delay":"4"},{"src":"name4","dest":"name6","delay":"6"},{"src":"name4","dest":"name6","delay":"6"}]}
Код:
#include <fstream>
#include "jsoncpp-master/include/json/json.h"
#include "jsoncpp-master/include/json/value.h"
#include "jsoncpp-master/include/json/writer.h"
#include "jsoncpp-master/include/json/config.h"
#include <iostream>
#include <string.h>
using namespace Json;
using namespace std;
int main() {
ifstream in("2.json");
Json::Reader reader;
Json::Value obj;
reader.parse(in,obj);
const Json::Value& edges=obj["edges"];
for (int i=0; i< edges.size(); i++) {
cout << "src : "<< edges[i]["scr"].asString()<<" ";
cout << "dest : "<< edges[i]["dest"].asString()<<" ";
cout << "delay : "<< edges[i]["delay"].asString()<<endl<<endl;
}
return 0;
}
Ошибки:
Scanning dependencies of target ParserJSON
[ 50%] Building CXX object CMakeFiles/ParserJSON.dir/main.cpp.obj
C:\Users\Anvar\CLionProjects\ParserJSON\main.cpp: In function 'int main()':
C:\Users\Anvar\CLionProjects\ParserJSON\main.cpp:16:18: warning: 'Json::Reader::Reader()' is deprecated: Use CharReader and CharReaderBuilder instead [-Wdeprecated-declarations]
Json::Reader reader;
^~~~~~
In file included from C:\Users\Anvar\CLionProjects\ParserJSON\jsoncpp-master/include/json/json.h:11,
from C:\Users\Anvar\CLionProjects\ParserJSON\main.cpp:3:
C:\Users\Anvar\CLionProjects\ParserJSON\jsoncpp-master/include/json/reader.h:56:3: note: declared here
Reader();
^~~~~~
[100%] Linking CXX executable ParserJSON.exe
CMakeFiles\ParserJSON.dir/objects.a(main.cpp.obj): In function `main':
C:/Users/Anvar/CLionProjects/ParserJSON/main.cpp:16: undefined reference to `Json::Reader::Reader()'
C:/Users/Anvar/CLionProjects/ParserJSON/main.cpp:17: undefined reference to `Json::Value::Value(Json::ValueType)'
C:/Users/Anvar/CLionProjects/ParserJSON/main.cpp:18: undefined reference to `Json::Reader::parse(std::istream&, Json::Value&, bool)'
C:/Users/Anvar/CLionProjects/ParserJSON/main.cpp:19: undefined reference to `Json::Value::operator[](char const*)'
C:/Users/Anvar/CLionProjects/ParserJSON/main.cpp:20: undefined reference to `Json::Value::size() const'
C:/Users/Anvar/CLionProjects/ParserJSON/main.cpp:21: undefined reference to `Json::Value::operator[](int) const'
C:/Users/Anvar/CLionProjects/ParserJSON/main.cpp:21: undefined reference to `Json::Value::operator[](char const*) const'
C:/Users/Anvar/CLionProjects/ParserJSON/main.cpp:21: undefined reference to `Json::Value::asString[abi:cxx11]() const'
C:/Users/Anvar/CLionProjects/ParserJSON/main.cpp:22: undefined reference to `Json::Value::operator[](int) const'
C:/Users/Anvar/CLionProjects/ParserJSON/main.cpp:22: undefined reference to `Json::Value::operator[](char const*) const'
C:/Users/Anvar/CLionProjects/ParserJSON/main.cpp:22: undefined reference to `Json::Value::asString[abi:cxx11]() const'
C:/Users/Anvar/CLionProjects/ParserJSON/main.cpp:23: undefined reference to `Json::Value::operator[](int) const'
C:/Users/Anvar/CLionProjects/ParserJSON/main.cpp:23: undefined reference to `Json::Value::operator[](char const*) const'
C:/Users/Anvar/CLionProjects/ParserJSON/main.cpp:23: undefined reference to `Json::Value::asString[abi:cxx11]() const'
C:/Users/Anvar/CLionProjects/ParserJSON/main.cpp:17: undefined reference to `Json::Value::~Value()'
C:/Users/Anvar/CLionProjects/ParserJSON/main.cpp:17: undefined reference to `Json::Value::~Value()'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [CMakeFiles\ParserJSON.dir\build.make:96: ParserJSON.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:67: CMakeFiles/ParserJSON.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:79: CMakeFiles/ParserJSON.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:117: ParserJSON] Error 2