c++ jsoncpp 读取 json 文件

c++ jsoncpp Reading json file

本文关键字:文件 json 读取 jsoncpp c++      更新时间:2023-10-16

我是 json 的新手,我试图从本教程站点读取我的 json 文件 https://en.wikibooks.org/wiki/JsonCpp

但是我收到一些链接器错误

1>------ 构建开始:项目:暮光冒险,配置:调试 Win32 ------ 1> 创建库 C:\Users\MinTeckNG\Desktop\TwilightAdventure\Debug\TwilightAdventure.lib 和对象 C:\Users\MinTeckNG\Desktop\TwilightAdventure\Debug\TwilightAdventure.exp 1>LoadMap.obj : 错误 LNK2019: 未解析的外部符号 "public: __thiscall Json::Reader::Reader(void)" (??0Reader@Json@@QAE@XZ) 在函数 "public: void __thiscall LoadMap::ReadJsonFileTest(void)" 中引用 (?ReadJsonFileTest@LoadingMap@@QAEXXZ) 1>C:\用户\MinTeckNG\桌面\暮光之城冒险\调试\暮光之城冒险.exe:致命错误LNK1120:1 个未解析的外部 =====

===== 构建:0 成功,1 失败,0 最新,0 跳过 ==========错误图片 LNK2019 未解析的外部符号

我的 JSON 文件要读取

{
"actors": [
{
"name": "Ground",
"pos": {
"x": 2592.0,
"y": 96.0
}
},
{
"name": "Grass",
"pos": {
"x": 2656.0,
"y": 96.0
}
}
}

我的代码

#include "LoadingMap.h"
#include <fstream>
LoadingMap::LoadingMap(void)
{
}
LoadingMap::~LoadingMap(void)
{
}
/*const char *LoadingMap::GetFileName(int stage, int difficulties)
{
char a = '0';
const char *ptr = &a;
return ptr;
}*/
/*void LoadingMap::ReadJsonFile(const char *filename)
{
}*/
void LoadingMap::ReadJsonFileTest()
{
std::ifstream ifs("1-1-0.json");
Json::Reader reader;
//Json::Value obj;
//reader.parse(ifs, obj); 
//std::cout << "Object type: " << obj["name"].asString() << std::endl;
//const Json::Value& pos = obj["pos"]; 
//std::cout << " x: " << pos[0]["x"].asUInt();
//std::cout << " y: " << pos[1]["y"].asUInt();
}

我的头文件

#pragma once
#include <iostream>
#include <fstream>
#include <json/json.h>
class LoadingMap
{
public:
LoadingMap(void);
~LoadingMap(void);
//const char *GetFileName(int stage, int difficulties);
//void ReadJsonFile(const char *filename);
void ReadJsonFileTest();
private:
};

好吧,代码主要是什么都没有,还没有实现,我只是尝试按照教程进行修改.

改为RapidJSON而不是jsoncpp。 现在一切似乎都很好。