Newer
Older
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "json-helper.h"
#include <QtGlobal>
#include <QDebug>
/*
* QVector<QString> <- QStringList
*/
QVector<QString> toQVector(const QStringList & qsl) {
QVector<QString> V;
for (auto & s : qsl)
V.push_back(s);
return V;
}
/*
* QVector<QString> -> QStringList
*/
QStringList toQStringList(const QVector<QString> & V) {
QStringList qsl;
for (auto & s : V)
qsl << s;
return qsl;
}
/*
* data for tables
*/
void toJSONtable(QJsonObject & jsonObj, const QString &ParameterName, const QVector<QStringList> & V) { // C-b-R
toJSON(jsonObj, ParameterName+".size", V.size());
for (int i=0; i<V.size(); i++)
toJSONstd(jsonObj, ParameterName+QString::number(i), toQVector(V[i]));
}
/*
*
*/
QJsonValue fromJSON(const QJsonObject & jsonObj, const QString &ParameterName) {
QJsonValue jsonValue = jsonObj.value(ParameterName);
if (jsonValue.isUndefined())
qDebug() << "*** ERROR: fromJSON(" + ParameterName + ")";
Q_ASSERT_X(not jsonValue.isUndefined(), "fromJSON", "jsonValue.isUndefined()");
return jsonValue;
}
/*
*
*/
QVector<QString> fromJSONqstr(const QJsonObject & jsonObj, const QString &ParameterName) {
int size = fromJSON(jsonObj, ParameterName+".size").toInt();
QVector<QString> V;
for (int i=0; i<size; i++)
V.push_back(fromJSON(jsonObj, ParameterName+QString::number(i)).toString());
return V;
}
/*
*
*/
QVector<QStringList> fromJSONtable(const QJsonObject & jsonObj, const QString &ParameterName) {
int size = fromJSON(jsonObj, ParameterName+".size").toInt();
QVector<QStringList> V;
for (int i=0; i<size; i++)
V.push_back(toQStringList(fromJSONqstr(jsonObj, ParameterName+QString::number(i))));
return V;
}