-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsonObject.cpp
More file actions
47 lines (35 loc) · 858 Bytes
/
JsonObject.cpp
File metadata and controls
47 lines (35 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "stdafx.h"
#include "JsonObject.h"
#include <qjsondocument.h>
JsonObject::JsonObject (const std::string& _fileName)
: fileName (_fileName)
{
}
bool JsonObject::LoadJson ()
{
std::string jsonFileName = "./JSON/" + fileName + ".json";
return LoadJson (jsonFileName);
}
bool JsonObject::LoadJson (const std::string& fileName)
{
QFile loadFile (fileName.c_str ());
bool ok = loadFile.open (QIODevice::ReadOnly);
if (ok)
{
QByteArray saveData = loadFile.readAll ();
QJsonDocument loadDoc (QJsonDocument::fromJson (saveData));
ReadJson (loadDoc.object ());
}
return ok;
}
void JsonObject::SaveToJson (const std::string& fileName)
{
QFile file (fileName.c_str ());
bool ok = file.open (QIODevice::OpenModeFlag::WriteOnly);
if (ok)
{
QJsonDocument doc (GetAsJsonObject());
file.write (doc.toJson());
file.close ();
}
}