使用json cpp 解析json文件時出現的問題
json 文件
{
"a": "1"
}
C++解析代碼
include <iostream>
#include <jsoncpp/json/json.h>
#include <fstream>
using namespace std;
int main(int argc, char **argv) {
ifstream ifs("conf.json");
Json::Reader jsonReader;
Json::Value jv;
if (!jsonReader.parse(ifs, jv)){
throw std::runtime_error("jsonReader service conf fail");
} else {
cout << "parse success" << endl;
}
}
解析總是出現錯誤,原因時json文件出現了問題。
{
"a": "1"//這裏的“1”前面多了一個空格導致的
}