Parse JSON directly from decimal uint8 vector #2321
-
|
Hi! To send it, I convert it with the
In the reply "resp" content, always in decimal characters, there is a text in JSON format like {"VarA":1000, "VarB":2000,...}. My purpose is to create an S-function (but more generally a code in C++) that taking in input the vector "resp", returns the values of VarA and VarB (1000 and 2000). My idea was to convert "resp" into a string and then pass it to the json:parse functions. Is this correct? Can it be done? More important: I also wonder if it is right to convert it into a string and then work on it...does anyone know if json::parse() can work directly on the uint_8 vector without the string conversion? Thank you everyone! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
|
You can pass an iterator range: #include <iostream>
#include "json.hpp"
using json = nlohmann::json;
int main()
{
std::vector<std::uint8_t> resp = {'f', 'o', 'o', '{', '"', 'V', 'a', 'r', '"', ':', '1', '0', '}'};
json j = json::parse(resp.begin() + 3, resp.end());
std::cout << j << std::endl;
}Output: {"Var":10} |
Beta Was this translation helpful? Give feedback.
You can pass an iterator range:
Output:
{"Var":10}