我在c ++中使用jsoncpp库来解析和创建json结构。我正在尝试编写json文件。我期待着这个:
[
{
"student" : {
"name" : "Julia",
"math" : [
{
"grade" : 10,
"day" : 23
},
{
"grade" : 10,
"day" : 23
}
]
}
}
]
我的代码:
Json::StyledWriter writer;
Json::Value val;
ofstream f("out.json", ios_base::out);
unsigned int c = 0;
val[c]["student"]["name"] = "Julia";
val[c]["student"]["math"] = Json::Value(Json::arrayValue); <== at this I'm opening [] brackets
val[c]["student"]["math"].append( {"grade":10, "day":23} ); <== and this I'm stuck, I've got an error, because I don't know how to do it right
将来它会被认为是很多学生,他们应该有很多分数。
答案 0 :(得分:0)
我不确定jsoncpp, 但是尝试这个怎么样?
... Json::Value element(Json::objectValue); element["grade"] = 10; element["day"] = 23; val[c]["student"]["math"].append(element); ...