git-svn-id: svn://192.168.0.12/source@21 8346c931-da38-4b9b-9d4c-e48b93cbd075
This commit is contained in:
22
Json/Json.pro
Normal file
22
Json/Json.pro
Normal file
@@ -0,0 +1,22 @@
|
||||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2015-02-11T18:41:42
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core
|
||||
|
||||
QT -= gui
|
||||
|
||||
TARGET = Json
|
||||
CONFIG += console
|
||||
CONFIG -= app_bundle
|
||||
|
||||
TEMPLATE = app
|
||||
|
||||
|
||||
SOURCES += main.cpp \
|
||||
sjson.cpp
|
||||
|
||||
HEADERS += \
|
||||
sjson.h
|
||||
16
Json/main.cpp
Normal file
16
Json/main.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include <QCoreApplication>
|
||||
#include "sjson.h"
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication a(argc, argv);
|
||||
QFile file;
|
||||
file.setFileName("test.txt");
|
||||
file.open(QIODevice::ReadOnly | QIODevice::Text);
|
||||
SJson test;
|
||||
QString str = test.Set(file.readAll(),"tea","babo");
|
||||
qDebug() << test.Set(str,"sig",false);
|
||||
file.close();
|
||||
return a.exec();
|
||||
}
|
||||
45
Json/sjson.cpp
Normal file
45
Json/sjson.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "sjson.h"
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
#include <QDebug>
|
||||
|
||||
SJson::SJson()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SJson::~SJson()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
17
Json/sjson.h
Normal file
17
Json/sjson.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef SJSON_H
|
||||
#define SJSON_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
class SJson
|
||||
{
|
||||
public:
|
||||
SJson();
|
||||
~SJson();
|
||||
QString Get(QString _str,QString _strKey);
|
||||
bool GetBool(QString _str,QString _strKey);
|
||||
QString Set(QString _str,QString _strKey,QString _strValue);
|
||||
QString Set(QString _str,QString _strKey,bool _bValue);
|
||||
};
|
||||
|
||||
#endif // SJSON_H
|
||||
Reference in New Issue
Block a user