You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Adding Values after call to clear() fails.
To Reproduce
Steps to reproduce the behavior:
1.
bool result = false;
Json::Value root;
Json::Reader reader;
result = reader.parse(request, request + strlen(request), root, false);
if (result)
{
std::string command;
int advanced;
try
{
command = root[0]["command"].asString();
advanced = root[0]["advanced"].asInt();
//Done with command
root.clear();
if (command.compare("GetStationDesc") == 0)
{
// If we use the root above after clear() this addition fails.
// Json::Value root;
root["name"] = "S2000Test";
root["type"] = "S2000";
Expected behavior
After the root.clear() I should be able to add items.
Desktop (please complete the following information):
OS: Embedded RTX with Keil compiler.
Meson version
Ninja version
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered:
Please always provide a full minimum working example when opening an issue – that is, the code should be ready to compile. In this particular case, you have omitted the content of the request variable, so the example does not compile straight out of the box, which makes it significantly harder to investigate.
Given that you are extracting information from root[0] before proceeding to the call to root.clear(), I assume that root contains a JSON array. Jsoncpp documentation for Value::clear() explicitly says that the value type remains unchanged after the call to clear(). So at the point where you are doing root["name"] = "S2000Test", you are assigning to an array as if it was an object. The library – correctly – rejects this attempt.
If you want to reuse root as an object, do root = Json::objectValue first.
The mistake clearly seems to be in the supplied code, not in the library, so the issue may be closed.
Describe the bug
Adding Values after call to clear() fails.
To Reproduce
Steps to reproduce the behavior:
1.
bool result = false;
Json::Value root;
Json::Reader reader;
result = reader.parse(request, request + strlen(request), root, false);
if (result)
{
std::string command;
int advanced;
try
{
command = root[0]["command"].asString();
advanced = root[0]["advanced"].asInt();
Expected behavior
After the root.clear() I should be able to add items.
Desktop (please complete the following information):
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: