Click here to Skip to main content
15,918,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
Hope all are doing good.
I have create a json payload and sending the payload.
My implementation is as follows.
Ex.:
C++
#include <iostream>
#include <json json.h="">
using namespace std;

#define ACTIVE "active"

class Test
{
    public:
    void testFun(Json::Value& payload)
    {
        if(payload.isMember(ACTIVE))
        {
            bool val = payload[ACTIVE].asBool();
        }
        else
        {
            std::cout<<"Not found"<<std::endl;
        }
    }
}

int main()
{
 test obj;
 json::value payload;
 payload["timestamp"]="12345" ;
 payload["keytimestamp"]="23456" payload["active"]="true;
 payload["data"]="payload" payload["command"]="put" 
 obj.testfun(payload);
}


for the above code, i am getting below error.
c++ exception with description "in json::value::find(key,end,found: requires objectvalue or nullvalue" thrown in body.
thank you

What I have tried:

I have create a json payload and sending the payload.
My implementation is as follows.
Ex.:
C++
#include <iostream>
#include <json json.h="">
using namespace std;

#define ACTIVE "active"

class Test
{
    public:
    void testFun(Json::Value& payload)
    {
        if(payload.isMember(ACTIVE))
        {
            bool val = payload[ACTIVE].asBool();
        }
        
        else
        {
            std::cout<<"Not found"<
Posted
Updated 10-Oct-22 7:37am
v2

1 solution

I tried to sort out the pre tags and all the ""= stuff but I think I missed a few and your class Test was only partially included.

I think your main function is missing a few semi-colons and a quote. Also, shouldn't the test object be of type Test?

This could be mostly a copy and paste problem but it's hard to tell.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900