C++ 断言'IsArray()';失败(RapidJSON)
今天早些时候,我测试了RapidJSON库,看看是否可以解析具有嵌套值的文档,但由于某种原因,我无法找到解决所遇到错误的方法。我在Google和Stack Overflow搜索了一两个小时,没有找到修复方法。以下是代码和错误: main.cpp:C++ 断言'IsArray()';失败(RapidJSON),c++,rapidjson,C++,Rapidjson,今天早些时候,我测试了RapidJSON库,看看是否可以解析具有嵌套值的文档,但由于某种原因,我无法找到解决所遇到错误的方法。我在Google和Stack Overflow搜索了一两个小时,没有找到修复方法。以下是代码和错误: main.cpp: #include <iostream> #include <SFML/Graphics.hpp> #include "rapidjson/document.h" #include "include.hpp" int main
#include <iostream>
#include <SFML/Graphics.hpp>
#include "rapidjson/document.h"
#include "include.hpp"
int main() {
unsigned int input = 1;
tile output;
output = LoadTile("../locations.json", input);
std::cout << output.x << std::endl;
return 0;
}
locations.json:
{
1:[
{"x":32},
{"y":32},
{"type":"water_c"}
]
}
错误:
test: /home/.../rapidjson/document.h:1547:rapidjson::GenericValue<Encoding, Allocator>::operator[](rapidjson::SizeType) [with Encoding = rapidjson::UTF8<>; Allocator = rapidjson::MemoryPoolAllocator<>; rapidjson::SizeType = unsigned int]: Assertion `IsArray()' failed.
Aborted (core dumped)
test:/home/../rapidjson/document.h:1547:rapidjson::GenericValue::operator[](rapidjson::SizeType)[带编码=rapidjson::UTF8;分配器=rapidjson::MemoryPoolAllocator;rapidjson::SizeType=unsigned int]:断言“IsArray()”失败。
中止(堆芯转储)
我知道这不是JSON格式,我什么都试过了。除非它真的有什么问题。我在Xubuntu 16.10上运行这个。感谢所有能提供帮助的人。您的JSON无效。在JSON中,键必须是字符串,用双引号编写。更多细节。 我建议使用来验证JSON字符串。 有效的JSON如下所示(1在双引号中):
cmake_minimum_required(VERSION 2.6)
project(test)
set(EXECUTABLE_NAME "test")
add_executable(${EXECUTABLE_NAME} main.cpp load.cpp include.hpp)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})
install(TARGETS ${EXECUTABLE_NAME} DESTINATION bin})
{
1:[
{"x":32},
{"y":32},
{"type":"water_c"}
]
}
test: /home/.../rapidjson/document.h:1547:rapidjson::GenericValue<Encoding, Allocator>::operator[](rapidjson::SizeType) [with Encoding = rapidjson::UTF8<>; Allocator = rapidjson::MemoryPoolAllocator<>; rapidjson::SizeType = unsigned int]: Assertion `IsArray()' failed.
Aborted (core dumped)
{
"1": [{
"x": 32
}, {
"y": 32
}, {
"type": "water_c"
}]
}