|
@@ -15,6 +15,8 @@
|
|
#include "fmtlog.h"
|
|
#include "fmtlog.h"
|
|
#include "LightLog.h"
|
|
#include "LightLog.h"
|
|
|
|
|
|
|
|
+#include "nlohmann/json.hpp"
|
|
|
|
+#define nJson nlohmann::json
|
|
|
|
|
|
Widget::Widget(QWidget *parent)
|
|
Widget::Widget(QWidget *parent)
|
|
: QWidget(parent)
|
|
: QWidget(parent)
|
|
@@ -34,6 +36,72 @@ Widget::~Widget()
|
|
delete ui;
|
|
delete ui;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/* 解析JSON示例 */
|
|
|
|
+void Widget::parseJSON()
|
|
|
|
+{
|
|
|
|
+ SPDLOG_INFO("解析JSON");
|
|
|
|
+
|
|
|
|
+ nJson json0;
|
|
|
|
+ json0["name"] = "microsoft";
|
|
|
|
+ json0["age"] = 18;
|
|
|
|
+ json0["bool"] = true;
|
|
|
|
+ json0["null"] = nullptr;
|
|
|
|
+ json0["array"] = {1, 2, 3, 4, 5};
|
|
|
|
+ json0["object"] = {{"key1", "value1"}, {"key2", "value2"}};
|
|
|
|
+
|
|
|
|
+ /* 打印json值 */
|
|
|
|
+ SPDLOG_INFO("json0: {}", json0.dump());
|
|
|
|
+
|
|
|
|
+ std::string name = json0["name"];
|
|
|
|
+ std::string name2 = json0["name"].get<std::string>();
|
|
|
|
+ std::string name1 = json0.at("name").get<std::string>();
|
|
|
|
+ std::string name5 = json0.at("name");
|
|
|
|
+ std::string name4 = json0.value("name", "default");
|
|
|
|
+
|
|
|
|
+ int age = json0["age"].get<int>();
|
|
|
|
+ bool b = json0["bool"];
|
|
|
|
+ nJson null = json0["null"];
|
|
|
|
+ nJson array = json0["array"];
|
|
|
|
+ nJson object = json0["object"];
|
|
|
|
+ /* 如果json中的值是null,在赋值给string时可能会报错,可以使用“?”运算符解决 */
|
|
|
|
+ std::string name3 = json0["name"].is_null() ? "" : json0["name"].get<std::string>();
|
|
|
|
+
|
|
|
|
+ /* 从直接到JSON */
|
|
|
|
+ nJson json1 = R"(
|
|
|
|
+ {
|
|
|
|
+ "name": "microsoft",
|
|
|
|
+ "age": 18,
|
|
|
|
+ "bool": true,
|
|
|
|
+ "null": null,
|
|
|
|
+ "array": [1, 2, 3, 4, 5],
|
|
|
|
+ "object": {
|
|
|
|
+ "key1": "value1",
|
|
|
|
+ "key2": "value2"
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ )"_json;
|
|
|
|
+
|
|
|
|
+ /* 或者 */
|
|
|
|
+ std::string str = R"(
|
|
|
|
+ {
|
|
|
|
+ "name": "microsoft",
|
|
|
|
+ "age": 18,
|
|
|
|
+ "bool": true,
|
|
|
|
+ "null": null,
|
|
|
|
+ "array": [1, 2, 3, 4, 5],
|
|
|
|
+ "object": {
|
|
|
|
+ "key1": "value1",
|
|
|
|
+ "key2": "value2"
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ )";
|
|
|
|
+ nJson json2 = nJson::parse(str);
|
|
|
|
+
|
|
|
|
+ /* 从JSON到字符串 */
|
|
|
|
+ std::string str1 = json0.dump();
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
|
|
void Widget::on_pBtn_connect_clicked()
|
|
void Widget::on_pBtn_connect_clicked()
|
|
{
|
|
{
|
|
@@ -54,7 +122,7 @@ void Widget::on_pBtn_downloadFile_clicked()
|
|
{
|
|
{
|
|
SPDLOG_INFO("点击了“下载文件”");
|
|
SPDLOG_INFO("点击了“下载文件”");
|
|
std::vector<std::string> fileList;
|
|
std::vector<std::string> fileList;
|
|
- bool ret = m_curlFtp.downloadFile("/SSD2/Video/哪吒之魔童降世.mp4", QApplication::applicationDirPath().toStdString() + "/哪吒之魔童降世.mp4");
|
|
|
|
|
|
+ bool ret = m_curlFtp.downloadFile("/SSD2/Video/哪吒之魔童降世.mp4", QApplication::applicationDirPath().toStdString() + "/YPM.mp4");
|
|
if(ret)
|
|
if(ret)
|
|
{
|
|
{
|
|
SPDLOG_INFO("下载成功");
|
|
SPDLOG_INFO("下载成功");
|
|
@@ -147,3 +215,17 @@ void Widget::on_pBtn_logSpeed_clicked()
|
|
SPDLOG_INFO("LightLog打印耗时: {}", lightLogTime.count());
|
|
SPDLOG_INFO("LightLog打印耗时: {}", lightLogTime.count());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+void Widget::on_pBtn_upload_clicked()
|
|
|
|
+{
|
|
|
|
+ SPDLOG_INFO("点击了“上传”");
|
|
|
|
+ bool ret = m_curlFtp.uploadFile(QApplication::applicationDirPath().toStdString() + "/YPM.mp4", "/SSD2/Video/YPM.mp4");
|
|
|
|
+ if(ret)
|
|
|
|
+ {
|
|
|
|
+ SPDLOG_INFO("上传成功");
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ SPDLOG_INFO("上传失败");
|
|
|
|
+ }
|
|
|
|
+}
|