V
V
Vladimir Krauz2016-08-09 16:03:01
JSON
Vladimir Krauz, 2016-08-09 16:03:01

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

1 answer(s)
S
Stanislav Makarov, 2016-08-09
@MelancholicTheDie

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 в файл
}

What are you trying to do in the above code, I did not understand. Regarding writing to a file - a separate story.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question