mirror of
https://github.com/minetest/irrlicht.git
synced 2025-02-22 22:00:26 +01:00
Entering the realm of JSON
who is jason?
This commit is contained in:
parent
d99208418f
commit
9483f17816
@ -5,6 +5,7 @@
|
|||||||
#include "path.h"
|
#include "path.h"
|
||||||
#include "json/json.hpp"
|
#include "json/json.hpp"
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
namespace irr
|
namespace irr
|
||||||
{
|
{
|
||||||
@ -17,6 +18,10 @@ void println(const char* data) {
|
|||||||
printf(data);
|
printf(data);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
const char * const boolToString(bool b)
|
||||||
|
{
|
||||||
|
return b ? "true" : "false";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Class methods.
|
// Class methods.
|
||||||
@ -49,11 +54,22 @@ IAnimatedMesh* CB3DJSONMeshFileLoader::createMesh(io::IReadFile* file) {
|
|||||||
// So here we turn this mangled disaster into a C string.
|
// So here we turn this mangled disaster into a C string.
|
||||||
|
|
||||||
// These two hold error message pointers, basically.
|
// These two hold error message pointers, basically.
|
||||||
std::string err {};
|
// std::string err {};
|
||||||
std::string warn {};
|
// std::string warn {};
|
||||||
|
|
||||||
// Try changing the type from auto to see why it's auto.
|
// Try changing the type from auto to see why it's auto.
|
||||||
auto buf = std::make_unique<char[]>(file->getSize());
|
auto buffer = std::make_unique<char[]>(file->getSize());
|
||||||
|
|
||||||
|
// Now we read that dang JSON.
|
||||||
|
file->read(buffer.get(), file->getSize());
|
||||||
|
|
||||||
|
const json data = json::parse("{\"hi\": 1}");
|
||||||
|
|
||||||
|
const auto test = data["hi"];
|
||||||
|
printf("is this a number? ");
|
||||||
|
println(boolToString(test.is_number()));
|
||||||
|
println(test.dump().c_str());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//! I'm sure this isn't a horrible idea!
|
//! I'm sure this isn't a horrible idea!
|
||||||
|
Loading…
x
Reference in New Issue
Block a user