C++ 从C+;中的文件解析json时出错+;使用jsonCpp库
我有一个JSON文件之类的东西C++ 从C+;中的文件解析json时出错+;使用jsonCpp库,c++,json,jsoncpp,C++,Json,Jsoncpp,我有一个JSON文件之类的东西 [{ "movie_id": 1, "rating": "9.3", "votes": "1,318,626", "description": "Two imprisoned men bond over a number ....", "title": "The Shawshank Redemption", "poster": "", "release_date": "14 October 1994", "metascore": "
[{
"movie_id": 1,
"rating": "9.3",
"votes": "1,318,626",
"description": "Two imprisoned men bond over a number ....",
"title": "The Shawshank Redemption",
"poster": "",
"release_date": "14 October 1994",
"metascore": "80",
"director": "Frank Darabont",
"storyline": "Andy Dufresne is a young and successful ...",
"stars": [ "Tim Robbins", "Morgan Freeman", "Bob Gunton" ],
"year": "1994",
"genre": [ "Crime", "Drama" ],
"gallery": [ "unknown1394846836._CB379391227_.png", ],
"running_time": "142min"
},
{...},
{...},...]
我想使用jsonCpp库解析上面文件input.json
中的数据,下面是我的代码
#include <bits/stdc++.h>
#include "json/json.h"
using namespace std;
int main(){
Json::Value root;
Json::Reader reader;
ifstream file("input.json");
file >> root;
string title = root[0]["title"].asString();
cout<<title;
return 0;
}
这里可能有什么问题,如何解决
提前感谢终于解决了!!我写我的问题的答案是为了帮助其他人 我没有正确地链接库,所以它给了我错误。你可以用C++的方式链接任何外部库。
json/json.h
和jsoncpp.cpp
main.cpp
,并写下使用此库的代码jsoncpp.cpp
json.h
文件和jsoncpp.cpp
,如下面我更新的代码所示g++main.cpp
#include <bits/stdc++.h>
#include "json/json.h"
#include "jsoncpp.cpp"
using namespace std;
int main(){
Json::Value root;
Json::Reader reader;
ifstream file("input.json");
file >> root;
string title = root[0]["title"].asString();
cout<<title<<"\n";
return 0;
}
终于解决了!!我写我的问题的答案是为了帮助其他人 我没有正确地链接库,所以它给了我错误。你可以用C++的方式链接任何外部库。
json/json.h
和jsoncpp.cpp
main.cpp
,并写下使用此库的代码jsoncpp.cpp
json.h
文件和jsoncpp.cpp
,如下面我更新的代码所示g++main.cpp
#include <bits/stdc++.h>
#include "json/json.h"
#include "jsoncpp.cpp"
using namespace std;
int main(){
Json::Value root;
Json::Reader reader;
ifstream file("input.json");
file >> root;
string title = root[0]["title"].asString();
cout<<title<<"\n";
return 0;
}
听起来你没有链接库?我想我已经链接了,但是为了确保你能简要告诉我链接库的过程吗?听起来你没有链接库?我想我已经链接了,但是为了确保你能简要告诉我链接库的过程吗?
The Shawshank Redemption