我搜索过这个特定的错误,但没有发现任何相关的问题。
我试图在我的.json项目中使用Rapidjson解析C++文件,我就是这样做的(遵循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控制台,但它在Win32中抛出一个Rapidjson断言
关键是它正在识别rapidjson文件,因为它找到了函数,并且不会抛出任何错误。但是,当我调试时,这就是doc对象在执行Parse()之后包含的内容
{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>...\include\rapidjson\encodedstream.h(88): warning C4512: 'rapidjson::EncodedInputStream<rapidjson::UTF8<char>,rapidjson::MemoryStream>' : assignment operator could not be generated
...\include\rapidjson\encodedstream.h(68) : see declaration of 'rapidjson::EncodedInputStream<rapidjson::UTF8<char>,rapidjson::MemoryStream>'
1>...\include\rapidjson\document.h(324): warning C4512: 'rapidjson::GenericStringRef<char>' : assignment operator could not be generated
...\include\rapidjson\document.h(1119) : see reference to class template instantiation 'rapidjson::GenericStringRef<char>' being compiled
1> ...\include\rapidjson\document.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> ...\include\rapidjson\document.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> ...\include\rapidjson\document.h(2010) : see reference to class template instantiation 'rapidjson::GenericValue<rapidjson::UTF8<char>,rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>>' being compiled
1> ...\src\main.cpp(17) : see reference to class template instantiation 'rapidjson::GenericDocument<rapidjson::UTF8<char>,rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>,rapidjson::CrtAllocator>' being compiled我认为读到这些警告是因为它不接受const char *,但在我所链接的教程中就是这样做的,它们没有显示出任何其他方式。
提前谢谢。
更新:
看起来这可能是文件的问题,但我不确定,也不知道如何避免它。我用创建了该文件,并将其保存为.json,并将其创建为中的.txt,结果相同。我也从JSON在线编辑下载了它,但是它不起作用,所以我几乎可以肯定还有另外一个问题我无法解决.
发布于 2016-03-23 02:05:27
在API Document::Parse(const char* json)中,参数json是包含JSON的字符串,而不是文件名。
你可以
Parse();或FILE*;或ifstream。对于大型JSON文件,2和3具有减少内存使用的优点。
https://stackoverflow.com/questions/36160719
复制相似问题