c++ - 为什么我第二次尝试将我的 JSON 更改为字符串不起作用(即使我有 breakpts 或 getchar,输出窗口也不会显示)?
问题描述
我正在尝试将我的 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;
}
}
解决方案
推荐阅读
- php - SQL:如何通过关注者找到类似的博客
- openedge - 我想使用 match 以便它匹配在模式之间或单词开头有空格或空格的特定模式
- android - recyclerView (kotlin) 的一项中的 4 个可点击视图
- laravel - 如何在 Laravel 中保存 iframe 内容?
- html - 如何在图像上添加文本并添加段落将使用 html、css 在同一行开始
- reactjs - 将 Material-ui 图标放在圆形进度指示器内
- r - 如果 NULL 或满足条件,则在 R 中继续
- command-line - 选择第 3 行并显示第 3 行 TextFile BatchScript
- python - Python中使用Eratosthenes筛子的质数
- c# - 检测 RichTextBox 中的强制行拆分