Quote Originally Posted by philmacu View Post
My guess is that I have done something really stupid with an escape character, any help would be appreciated, so my code, I create a QString that holds the curl command:
Qt Code:
  1. jsonAuthenticate = "curl -d";
  2. jsonAuthenticate += " "{ "jsonrpc": "2.0", "id": 1, "method": "call", "params": [ "00000000000000000000000000000000", "session", "login", { "username": "root", "password": "********" } ] }"";
  3. jsonAuthenticate += " [url]http://192.168.2.1/ubus[/url] ";
To copy to clipboard, switch view to plain text mode 
Assuming jsonAuthenticate is a QString the code above will not compile.

Qt Code:
  1. g++ -c -pipe -O2 -Wall -W -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I. -I. -isystem /usr/include/qt5 -isystem /usr/include/qt5/QtGui -isystem /usr/include/qt5/QtCore -I. -isystem /usr/include/libdrm -I/usr/lib64/qt5/mkspecs/linux-g++ -o main.o main.cpp
  2. main.cpp: In function ‘int main(int, char**):
  3. main.cpp:9:28: error: expected ‘;’ before ‘{’ token
  4. jsonAuthenticate += " "{ "jsonrpc": "2.0", "id": 1, "method": "call", "params": [ "00000000000000000000000000000000", "session", "login", { "username": "root", "password": "********" } ] }"";
  5. ^
  6. main.cpp:9:195: warning: statement has no effect [-Wunused-value]
  7. ": [ "00000000000000000000000000000000", "session", "login", { "username": "root", "password": "********" } ] }"";
  8. ^
  9. make: *** [Makefile:768: main.o] Error 1
To copy to clipboard, switch view to plain text mode 

You need to escape the double quotes embedded in the double-quoted string, or build the JSON object using QJsonObject and QJsonDocument. It's also possible that the double-quote preceding/trailing the outermost braces {} within the JSON are syntactically incorrect..
Qt Code:
  1. QString jsonAuthenticate;
  2. jsonAuthenticate = "curl -d";
  3. jsonAuthenticate += " \"{ \"jsonrpc\": \"2.0\", \"id\": 1, \"method\": \"call\", \"params\": [ \"00000000000000000000000000000000\", \"session\", \"login\", { \"username\": \"root\", \"password\": \"********\" } ] }\" ";
  4. jsonAuthenticate += " http://192.168.2.1/ubus ";
To copy to clipboard, switch view to plain text mode