我正在尝试将我的 JSON 对象转换为测试用例 1 和 4 中的字符串。删除测试用例 4 后,代码可以正常工作,就像输出显示一样。但是当我包含测试用例 4 时,代码将无法运行。VS Code 说分段错误。我尝试j.get<decltype(s)>()
为两者都做,代码会编译,但输出不会显示。有什么解决办法吗?
#include "records_manager_test.hpp"
#include "records_manager.hpp"
#include "nlohmann/json.hpp"
using json = nlohmann::json;
bool RecordsManagerTest::test1(){ //To test JSON
json j = {
{"1", {
{"CategoryID",67},
{"PatientID",90},
{"Name","Foo"},
{"Address","Bar"},
{"DOB","100980"}
}},
{"2",{
{"CategoryID", 6},
{"PatientID", 9},
{"Name", "Ryan"},
{"Address", "161 University Ave"},
{"DOB", "180998"}
}}
};
string s = j.dump(4); //Stringfying JSON
RecordsManager test(s);
if(test.insertRecord(89,89,"Eric","161 University Avenue","010195"));
{
test.printAsJSON();
return true;
}
}
bool RecordsManagerTest::test2(){ // To test insert of record
RecordsManager test;
if(test.insertRecord(88,89,"Eric","161 University Avenue","040485")){
if(test.insertRecord(88,90,"Ryan","161 University Avenue","160695")){
return true;
}
}
return false;
}
bool RecordsManagerTest::test3(){ //To test removal of record
RecordsManager test;
test.insertRecord(88,89,"Eric","dfdf","46465");
test.insertRecord(88,90,"Eric","dfdf","46465");
if(test.removeRecord(89,89))
{
test.printAsJSON();
return true;
}
return false;
}
bool RecordsManagerTest::test4(){ //To test JSON
json j = {
{"1", {
{"CategoryID",67},
{"PatientID",90},
{"Name","Foo"},
{"Address","Bar"},
{"DOB","100980"}
}},
{"2",{
{"CategoryID", 6},
{"PatientID", 9},
{"Name", "Ryan"},
{"Address", "161 University Ave"},
{"DOB", "180998"}
}}
};
//Stringfying JSON
string s1 = j.dump(4);
RecordsManager test(s1);
if(test.insertRecord(89,89,"Eric","161 University Avenue","010195"));
{
test.printAsJSON();
return true;
}
}