0

I want something like the below in json c++ code

{
"Numofbooks": 2
"book1": { "title":"saaas", "ISBN":234234, "author":"sdjjh"}
"book2": { "title":"fdfrg", "ISBN":8978, "author":"dttt"}
}

I have already checked this link and it this, but it doesnt show how to do it in C++ code. I am using this JSON CPP library, http://jsoncpp.sourceforge.net.

So to code I should do something like belo

Json::objectvalue obj;
obj[numofbooks] = 2;

Next how do I fill this list of book1 and book2?? I am not getting this..Please advice

1 Answer 1

2
Json::Value arr(Json::arrayValue);

arr.append("a");
arr.append("b");
arr.append(1000);

Json::Value obj;

obj["a"] = "aa";
obj["b"] = 1000;
obj["c"] = arr;

std::cout << arr.toStyledString() << std::endl;
std::cout << obj.toStyledString() << std::endl;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.