-
Hello dear normann, I have a pre-assembled json that gives a strange error when broken down, what could be the reason? There are no problems with dataResultNew["data"], it unloads as a string. Screenshot with an error in the attachment struct DataItem
{
std::string ID = "";
std::string Parent = "";
std::string ParentEnabled = "";
};
void from_json(const nlohmann::json& j, DataItem& d) {
j.at("id").get_to(d.ID);
j.at("parent").get_to(d.Parent);
j.at("parentEnabled").get_to(d.ParentEnabled);
}
std::vector<std::string> split(const std::string& s, char delimiter) {
std::vector<std::string> tokens;
std::string token;
std::istringstream tokenStream(s);
while (std::getline(tokenStream, token, delimiter)) {
tokens.push_back(token);
}
return tokens;
}
int main()
{
///
std::string dataSuperString = dataResultNew["data"].dump();
auto dataSuper = json::parse(dataSuperString.c_str()).get<std::vector<DataItem>>();
for (const auto& d : dataSuper)
{
if (!d.Parent.empty())
{
auto parents = split(d.Parent, ',');
for (const auto& p : parents) {
parentToChildren[p].push_back(d.ID);
childToParent[d.ID] = p;
}
}
}
return 0;
} |
Beta Was this translation helpful? Give feedback.
Answered by
gregmarr
Apr 2, 2024
Replies: 1 comment 1 reply
-
What's your call stack? This is telling you that you are trying to read an array, but you're reading something else. There isn't enough information there to see what it is that you're trying to read. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Kolhun
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What's your call stack? This is telling you that you are trying to read an array, but you're reading something else. There isn't enough information there to see what it is that you're trying to read.