Make the input parsing a bit more flexible with regards to a newline on the end of the input JSON or not.

This commit is contained in:
Ken Moore
2016-05-18 08:59:04 -04:00
parent 68793175f7
commit 02d6a326e4
2 changed files with 3 additions and 1 deletions

View File

@@ -44,6 +44,7 @@ RestInputStruct::RestInputStruct(QString message, bool isRest){
//Now Parse out the Body into the JSON fields and/or arguments structure
//NOTE: if the body of the message is encrypted, then it needs to be decrypted outside the struct first,
// then run the "ParseBodyIntoJson()" function to read/convert the data as needed.
qDebug() << "Got request:" << message << isRest << Header << bridgeID;
if(Header.isEmpty() || isRest){ //no other data processing needed
ParseBodyIntoJson();
}
@@ -52,6 +53,7 @@ RestInputStruct::RestInputStruct(QString message, bool isRest){
RestInputStruct::~RestInputStruct(){}
void RestInputStruct::ParseBodyIntoJson(){
if(Body.endsWith("\n")){ Body.chop(1); }
if(Body.startsWith("{") && Body.endsWith("}") ){
QJsonDocument doc = QJsonDocument::fromJson(Body.toUtf8());
if(!doc.isNull() && doc.isObject() ){

View File

@@ -175,7 +175,7 @@ void WebSocket::EvaluateREST(QString msg){
}
void WebSocket::EvaluateRequest(const RestInputStruct &REQ){
//qDebug() << "Evaluate Request:" << REQ.namesp << REQ.name << REQ.args;
qDebug() << "Evaluate Request:" << REQ.namesp << REQ.name << REQ.args;
RestOutputStruct out;
out.in_struct = REQ;
QHostAddress host;