Skip to content

comparing Json string #762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Bishalsahoo opened this issue Apr 12, 2018 · 7 comments
Closed

comparing Json string #762

Bishalsahoo opened this issue Apr 12, 2018 · 7 comments

Comments

@Bishalsahoo
Copy link

Bishalsahoo commented Apr 12, 2018

I am facing problem with comparing two or more json string that will be passed to my function as argument, if anyone can help me with completing the code that will be helpful as I was trying the Value::const_iterator but its showing error.Kinda a newbee in the use of jsoncpp , will appreciate if anyone can help.
the aim is to compare the temp with item1 and item2 and return true or false if both equal.
the code:

bool validate::isEqualItem(std::string item1, std::string item2, std::string temp) {

    string i=item1;
    string j=item2;
    string temp1=temp;
    Value root,root1,root2;
    Reader reader,reader1,reader2;
    bool parsingSuccessful = reader.parse(i, root )&&reader1.parse(j,root1)&&reader2.parse(temp1,root2);
    if ( !parsingSuccessful )
    {
       return false;
    }
  for(Value::const_iterator order =root2.begin();order!=root2.end();order++){
    //showing error in order!=root2.end error is cannot compare structures
  }
}

Test cases: isEqualItem({id: 1, name: "test", randomNo: 1}, {id: 1, name: "test", randomNo: 1}, {id: null, name: null, randomNo: null}) //should assert true

isEqualItem({id: 1, name: "test", randomNo: 1}, {id: 1, name: "test", randomNo: 2}, {id: null, name: null, randomNo: null}) //should assert false

isEqualItem({id: 1, name: "test", randomNo: 1}, {id: 1, name: "test", randomNo: 3}, {id: null, name: null}) //should assert true

@Bishalsahoo
Copy link
Author

@cdunn2001 Can you please help me with this ? Or anyone ?

@cdunn2001
Copy link
Contributor

Please use CharReader. Or simply operator>>(std::istream)

Is there a bug in the iterator? If so, please file a report. It should be possible to walk through the keys instead, and simple compare values.

@Bishalsahoo
Copy link
Author

yes thats what I want , to walk through the keys and compare values. I have sent you the description to your email please help me with that , its an urgent necessity

@cdunn2001
Copy link
Contributor

@Bishalsahoo
Copy link
Author

I have tried to implement that but I am unable to compare the keys and values of entire json strings , It will be a great help if I can get a working code that could function according to the above mentioned Test cases , I am totally stuck .

@BillyDonahue
Copy link
Contributor

@cdunn2001
Copy link
Contributor

Thanks. Updated FAQ.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants