Rapidjson未读取文件
Rapidjson not reading file
我已经搜索了这个特定的错误,但没有找到任何相关的问题。
我正试图在我的C++项目中使用Rapidjson来解析.json文件,这就是我的做法(遵循Rapidjson教程的说明):
main.cpp
#include "../include/rapidjson/document.h"
...
using namespace rapidjson;
int main() {
...
Document doc;
doc.Parse("data/entities.json");
if (doc.HasMember("DreadNought") { ... }
...
}
if语句的预期结果是将某些内容打印到Win32控制台,但它在document.h
内部抛出了一个Rapidjson
断言。
关键是它识别rapidjson
文件,因为它可以找到函数,并且不会抛出任何错误。然而,当我调试时,执行Parse()
后,doc
对象包含的内容
{data_={s={length=0 hashcode=0 str=0x00000000 <NULL> } ss={str=0x0124fa30 "" } n={i={i=0 padding=0x0124fa34 "" } ...} ...} }
0x0321ec30 {chunkHead_=0x00000000 <NULL> chunk_capacity_=65536 userBuffer_=0x00000000 ...}
doc
对象内的所有字段都具有NULL
值。请注意,我已经尝试过Parse<0>()
,除非我不知道这意味着什么,否则结果完全相同。
这不是路径问题,因为我对图像和其他数据使用相同的路径(data/
),并且它们被找到了。
我从编译器那里得到的唯一信息是一些我无法破译的警告。
1>...includerapidjsonencodedstream.h(88): warning C4512: 'rapidjson::EncodedInputStream<rapidjson::UTF8<char>,rapidjson::MemoryStream>' : assignment operator could not be generated
...includerapidjsonencodedstream.h(68) : see declaration of 'rapidjson::EncodedInputStream<rapidjson::UTF8<char>,rapidjson::MemoryStream>'
1>...includerapidjsondocument.h(324): warning C4512: 'rapidjson::GenericStringRef<char>' : assignment operator could not be generated
...includerapidjsondocument.h(1119) : see reference to class template instantiation 'rapidjson::GenericStringRef<char>' being compiled
1> ...includerapidjsondocument.h(1118) : while compiling class template member function 'rapidjson::GenericMemberIterator<false,Encoding,Allocator> rapidjson::GenericValue<Encoding,Allocator>::FindMember(const char *)'
1> with
1> [
1> Encoding=rapidjson::UTF8<char>
1> , Allocator=rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>
1> ]
1> ...includerapidjsondocument.h(1123) : see reference to function template instantiation 'rapidjson::GenericMemberIterator<false,Encoding,Allocator> rapidjson::GenericValue<Encoding,Allocator>::FindMember(const char *)' being compiled
1> with
1> [
1> Encoding=rapidjson::UTF8<char>
1> , Allocator=rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>
1> ]
1> ...includerapidjsondocument.h(2010) : see reference to class template instantiation 'rapidjson::GenericValue<rapidjson::UTF8<char>,rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>>' being compiled
1> ...srcmain.cpp(17) : see reference to class template instantiation 'rapidjson::GenericDocument<rapidjson::UTF8<char>,rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>,rapidjson::CrtAllocator>' being compiled
阅读这些警告时,我认为它不接受const char *
,但我链接的教程就是这样做的,它们没有以任何其他方式显示。
提前谢谢。
更新:
这个文件似乎有问题,但我不确定,也不知道如何避免。我用Visual Studio代码创建了这个文件,并将其保存为.json,我从Windows资源管理器中将其创建为.txt,结果相同。我也从JSON编辑器在线下载了它,但它不起作用,所以我几乎可以肯定还有另一个问题我无法解决。。。
在API Document::Parse(const char* json)
中,参数json
是包含JSON的字符串,而不是文件名。
你可以选择
- 自己将JSON文件加载成字符串,然后调用
Parse()
;或 - 将CCD_ 14与封装CCD_ 16的CCD_;或
- 将CCD_ 17与封装CCD_ 19的CCD_
对于大型JSON文件,2和3具有减少内存使用的优势。
相关文章:
- 正在将csv文件读取为双精度矢量
- 将从格式化文本文件读取的文本数据存储到链表
- C++ 读取文件读取文件不正确
- 使用对象文件读取三角形数据网格
- 如何减慢从 BVH 文件读取的 opengl 动画?
- 从文件读取,并写入函数C++中的数组
- 从对象C++中的文件读取内容时出现分段错误
- 从文件读取并通过矢量输出到控制台
- 尝试将字符串从文件读取到无符号字符向量中
- 如何将文本文件读取到二维数组中并以 c++ 打印
- 简化文件读取的函数
- 如何将逗号分隔的文件读取为 2D int 数组?
- 在 c++ 中将数据从文件读取到队列中
- 'std::wstring_convert'尽可能多地转换(从 UTF8 文件读取块)
- C++,从文件读取到结构,然后读取到向量(结构被推入向量太多次,而不仅仅是一次)
- 文件读取C++包括空格键
- 从文件读取时未将值推回矢量
- 从文件 C++ 读取时的无限循环
- 从同一文件读取和写入?
- 从.txt文件读取到C++中的双精度向量