66 lines
1.6 KiB
C++
66 lines
1.6 KiB
C++
#include "sjson.h"
|
|
#include <QJsonDocument>
|
|
#include <QJsonObject>
|
|
#include <QJsonArray>
|
|
#include <QDebug>
|
|
|
|
SJson::SJson()
|
|
{
|
|
|
|
}
|
|
|
|
SJson::~SJson()
|
|
{
|
|
|
|
}
|
|
|
|
QString SJson::Sql(QString _str)
|
|
{
|
|
_str = _str.replace("\"","\\\"");
|
|
_str = _str.replace("'","\\'");
|
|
//_str = _str.replace(",","\\,");
|
|
return _str;
|
|
}
|
|
|
|
QString SJson::Get(QString _str,QString _strKey)
|
|
{
|
|
return QJsonDocument::fromJson(_str.toUtf8()).object().value(_strKey).toString();
|
|
}
|
|
|
|
bool SJson::GetBool(QString _str,QString _strKey)
|
|
{
|
|
return QJsonDocument::fromJson(_str.toUtf8()).object().value(_strKey).toBool();
|
|
}
|
|
|
|
int SJson::GetNumber(QString _str,QString _strKey)
|
|
{
|
|
return QJsonDocument::fromJson(_str.toUtf8()).object().value(_strKey).toInt();
|
|
}
|
|
|
|
QString SJson::Set(QString _str,QString _strKey,QString _strValue)
|
|
{
|
|
QJsonDocument doc = QJsonDocument::fromJson(_str.toUtf8());
|
|
QJsonObject obj = doc.object();
|
|
obj.insert(_strKey,QJsonValue(_strValue));
|
|
doc.setObject(obj);
|
|
return doc.toJson();
|
|
}
|
|
|
|
QString SJson::Set(QString _str,QString _strKey,bool _bValue)
|
|
{
|
|
QJsonDocument doc = QJsonDocument::fromJson(_str.toUtf8());
|
|
QJsonObject obj = doc.object();
|
|
obj.insert(_strKey,QJsonValue(_bValue));
|
|
doc.setObject(obj);
|
|
return doc.toJson();
|
|
}
|
|
|
|
QString SJson::Set(QString _str,QString _strKey,int _nValue)
|
|
{
|
|
QJsonDocument doc = QJsonDocument::fromJson(_str.toUtf8());
|
|
QJsonObject obj = doc.object();
|
|
obj.insert(_strKey,QJsonValue(_nValue));
|
|
doc.setObject(obj);
|
|
return doc.toJson();
|
|
}
|