first json parse code

This commit is contained in:
Rafael 2016-03-21 20:44:07 +01:00
parent 1462f9ef1c
commit 4050358462
14 changed files with 99 additions and 7 deletions

View file

@ -19,11 +19,18 @@
#include "PictureDialog.h"
#include "ui_PictureDialog.h"
#include <QJsonDocument>
#include <QJsonObject>
#include <QVariantMap>
#include <QJsonArray>
#include <QDebug>
PictureDialog::PictureDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::PictureDialog)
{
ui->setupUi(this);
jsonDrawString = ui->labJSON->text();
}
PictureDialog::~PictureDialog()
@ -35,3 +42,38 @@ void PictureDialog::setSnapmaticPicture(QPixmap pixmap)
{
ui->labPicture->setPixmap(pixmap);
}
void PictureDialog::setJsonString(QString jsonStr)
{
QJsonDocument jsonDocument = QJsonDocument::fromJson(jsonStr.toLatin1());
QJsonObject jsonObject = jsonDocument.object();
QVariantMap jsonMap = jsonObject.toVariantMap();
QString locX;
QString locY;
QString locZ;
QStringList plyrsList;
if (jsonMap.contains("loc"))
{
QJsonObject locObject = jsonObject["loc"].toObject();
QVariantMap locMap = locObject.toVariantMap();
if (locMap.contains("x")) { locX = locMap["x"].toString(); }
if (locMap.contains("y")) { locY = locMap["y"].toString(); }
if (locMap.contains("z")) { locZ = locMap["z"].toString(); }
}
if (jsonMap.contains("plyrs"))
{
plyrsList = jsonMap["plyrs"].toStringList();
}
QString plyrsStr;
foreach (const QString &player, plyrsList)
{
plyrsStr.append(", ");
plyrsStr.append(player);
}
if (plyrsStr.length() >= 1) { plyrsStr.remove(0,2); }
ui->labJSON->setText(jsonDrawString.arg(locX, locY, locZ, plyrsStr));
}

View file

@ -32,10 +32,12 @@ class PictureDialog : public QDialog
public:
explicit PictureDialog(QWidget *parent = 0);
void setSnapmaticPicture(QPixmap pixmap);
void setJsonString(QString jsonStr);
~PictureDialog();
private:
Ui::PictureDialog *ui;
QString jsonDrawString;
};
#endif // PICTUREDIALOG_H

View file

@ -33,6 +33,14 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labJSON">
<property name="text">
<string>Location: X: %1 Y: %2 Z: %3
Players: %4</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>

View file

@ -92,15 +92,12 @@ bool SnapmaticPicture::readingPicture()
if (!picFile->isReadable())
{
lastStep = "2;/3,ReadingFile," + convertDrawStringForLog(picFileName) + ",3,NOJSON";
qDebug() << lastStep;
}
else if (picFile->read(4) != "JSON")
{
lastStep = "2;/3,ReadingFile," + convertDrawStringForLog(picFileName) + ",3,CTJSON";
qDebug() << lastStep;
}
QByteArray jsonRawContent = picFile->read(jsonStreamLength);
qDebug() << jsonRawContent.toHex();
jsonStr = getSnapmaticJSONString(jsonRawContent);
return cachePicture.loadFromData(jpegRawContent);
@ -111,7 +108,7 @@ QString SnapmaticPicture::getSnapmaticPictureString(QByteArray snapmaticHeader)
QByteArray snapmaticUsefulBytes = snapmaticHeader.left(snapmaticUsefulLength);
snapmaticUsefulBytes.replace(QByteArray::fromHex("00"),"");
snapmaticUsefulBytes.replace(QByteArray::fromHex("01"),"");
return QString::fromAscii(snapmaticUsefulBytes);
return QString::fromLatin1(snapmaticUsefulBytes);
}
QString SnapmaticPicture::getSnapmaticJSONString(QByteArray jsonBytes)
@ -119,7 +116,7 @@ QString SnapmaticPicture::getSnapmaticJSONString(QByteArray jsonBytes)
QByteArray jsonUsefulBytes = jsonBytes;
jsonUsefulBytes.replace(QByteArray::fromHex("00"),"");
jsonUsefulBytes.replace(QByteArray::fromHex("0C"),"");
return QString::fromAscii(jsonUsefulBytes);
return QString::fromLatin1(jsonUsefulBytes);
}
bool SnapmaticPicture::readingPictureFromFile(QString fileName)

32
app.rc Executable file
View file

@ -0,0 +1,32 @@
//IDI_ICON1 ICON DISCARDABLE "gta5sync.ico"
#include <windows.h>
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1, 0, 0, 0
PRODUCTVERSION 1, 0, 0, 0
FILEFLAGSMASK 0x3fL
FILEFLAGS 0
FILEOS VOS_NT_WINDOWS32
FILETYPE VFT_APP
FILESUBTYPE VFT2_UNKNOWN
BEGIN
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0409, 1200
END
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", "Syping Gaming Team\0"
VALUE "FileDescription", "Grand Theft Auto V Sync\0"
VALUE "FileVersion", "1.0.0.0\0"
VALUE "InternalName", "gta5sync\0"
VALUE "LegalCopyright", "Copyright © 2015-2016 Syping Gaming Team\0"
VALUE "OriginalFilename", "gta5sync.exe\0"
VALUE "ProductName", "Grand Theft Auto V Sync\0"
VALUE "ProductVersion", "1.0.0.0\0"
END
END
END

View file

@ -19,6 +19,7 @@
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets json
isEqual(QT_MAJOR_VERSION, 5): DEFINES += QT5_MODE
TARGET = gta5sync
TEMPLATE = app
@ -37,7 +38,9 @@ FORMS += \
RESOURCES +=
OTHER_FILES +=
OTHER_FILES += app.rc
win32: RC_FILE += app.rc
# QT4 ONLY STUFF

View file

@ -48,9 +48,10 @@ int main(int argc, char *argv[])
qDebug() << picture.readingPictureFromFile(arg1);
qDebug() << picture.getLastStep();
PictureDialog picDialog;
picDialog.setWindowFlags(picDialog.windowFlags()^Qt::WindowContextHelpButtonHint);
picDialog.setWindowTitle(picture.getPictureStr());
qDebug() << picture.getJsonStr();
picDialog.setSnapmaticPicture(picture.getPixmap());
picDialog.setJsonString(picture.getJsonStr());
picDialog.show();
return a.exec();

1
qjson4/QJsonArray Executable file
View file

@ -0,0 +1 @@
#include "QJsonArray.h"

1
qjson4/QJsonDocument Executable file
View file

@ -0,0 +1 @@
#include "QJsonDocument.h"

1
qjson4/QJsonObject Executable file
View file

@ -0,0 +1 @@
#include "QJsonObject.h"

1
qjson4/QJsonParseError Executable file
View file

@ -0,0 +1 @@
#include "QJsonParseError.h"

1
qjson4/QJsonRoot Executable file
View file

@ -0,0 +1 @@
#include "QJsonRoot.h"

1
qjson4/QJsonValue Executable file
View file

@ -0,0 +1 @@
#include "QJsonValue.h"

1
qjson4/QJsonValueRef Executable file
View file

@ -0,0 +1 @@
#include "QJsonValueRef.h"