Answer the question
In order to leave comments, you need to log in
C++ How to get an array from nested JSON (JSONCPP) and write it to a file keeping the data binary?
Good afternoon.
I don't understand why my last question was deleted, but I'll ask it again.
How to get array from nested JSON? (I use the jsoncpp library)
JSON itself:
{"buffer":{"type":"Buffer","data":[115,100,97,115,100,0,0,0,2,0]}}
I need, as you understand, get data from data. And then write this data to a file, but at the same time preserving the binary nature of the file. (Is the ios::binary flag enough?)
Tried to get it like this:
const char* buffer = jsonObject["buffer"].get("data", (const char*)("")).asCString();
But then LogicError, then segmentation error.
Answer the question
In order to leave comments, you need to log in
It did not work with jsoncpp, the code is written according to the source code of the library:
for (const auto v : jsonObject["buffer"]["data"]) {
const std::uint8_t b = static_cast<std::uint8_t>(v.asInt());
// пишете b в файл
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question