Tôi đã mã sau:Tạo mảng json trống với jsoncpp
void MyClass::myMethod(Json::Value& jsonValue_ref)
{
for (int i = 0; i <= m_stringList.size(); i++)
{
if (m_boolMarkerList[i])
{
jsonValue_ref.append(stringList[i]);
}
}
}
void MyClass::myOuterMethod()
{
Json::Value jsonRoot;
Json::Value jsonValue;
myMethod(jsonValue);
jsonRoot["somevalue"] = jsonValue;
Json::StyledWriter writer;
std::string out_string = writer.write(jsonRoot);
}
Nếu tất cả boolMarkers là sai sự out_string là { "somevalue": null} nhưng tôi muốn nó là một mảng trống: { "somevalue" : []}
Có ai biết cách đạt được điều này không?
Cảm ơn bạn rất nhiều!
lý do tại sao không chỉ 'jsonRootValue [" emptyArray "] = Json :: arrayValue'; –
Tôi nghĩ có lẽ khi tôi đăng câu hỏi này - hai năm trước khi bình luận của bạn - đó là điều không thể. –