Need help parsing Tiled's json export with c++

I’m not too terribly good with JSON yet, this is my first time figuring out. I haven’t found a library that is simple enough for me and good enough to do what I need. I’ve tried rapidjson to some success, but I can’t figure out how to access the layers individually with that.

Once you have found a library you can use to parse JSON files, getting the layers would be something like this (taking Qt 5 JSON support as example):

// dummy incomplete json map
QByteArray json("{ \"layers\": [ { \"name\":\"Layer 1\", \"data\":[30, 30] } ] }");

QJsonDocument doc = QJsonDocument::fromJson(json);
QJsonObject map = doc.object();
QJsonArray layers = map.value("layers").toArray();
QJsonObject firstLayer = layers.at(0).toObject();
QJsonArray layerData = firstLayer.value("data").toArray();

QString firstLayerName = firstLayer.value("name").toString();
unsigned firstGlobalTileId = (unsigned) layerData.at(0).toInt();

qDebug() << firstLayerName << firstGlobalTileId;

It outputs:

"Layer 1" 30

Qt doesn’t work on my school’s computers. Is there another library or a way to strictly use just the json part of Qt?

There is no way to just use the JSON part of Qt, but there are plenty of other JSON libraries out there. But since I never used any, there’s none I can recommend. I’d suggest having a look yourself or maybe just start at http://json.org/, it lists over a dozen C++ libraries (and of course you could use a C library in C++ as well, so you have a lot of choice).

I’ve tried all of those, they’re too complicated for what I need.

Hmm, could it be that you just don’t know C++ very well yet? It’s not a language I would recommend to start with, unless you first focus for at least a month on just learning the language.

If you really need to do it in C++, I had a short look through the list and JSON++ looked to me like a very sensible one since it doesn’t depend on additional libraries and uses familiar C++ data types like std::map and std::vector. Though since you mention “school’s computers”, I really hope they run Linux. If it’s Windows, maybe this will work for the Flex/Bison dependency: https://sourceforge.net/projects/winflexbison/.