Originally Posted by
philmacu
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:
jsonAuthenticate = "curl -d";
jsonAuthenticate += " "{ "jsonrpc": "2.0", "id": 1, "method": "call", "params": [ "00000000000000000000000000000000", "session", "login", { "username": "root", "password": "********" } ] }"";
jsonAuthenticate += " [url]http://192.168.2.1/ubus[/url] ";
jsonAuthenticate = "curl -d";
jsonAuthenticate += " "{ "jsonrpc": "2.0", "id": 1, "method": "call", "params": [ "00000000000000000000000000000000", "session", "login", { "username": "root", "password": "********" } ] }"";
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.
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
main.cpp: In function ‘int main(int, char**)’:
main.cpp:9:28: error: expected ‘;’ before ‘{’ token
jsonAuthenticate += " "{ "jsonrpc": "2.0", "id": 1, "method": "call", "params": [ "00000000000000000000000000000000", "session", "login", { "username": "root", "password": "********" } ] }"";
^
main.cpp:9:195: warning: statement has no effect [-Wunused-value]
": [ "00000000000000000000000000000000", "session", "login", { "username": "root", "password": "********" } ] }"";
^
make: *** [Makefile:768: main.o] Error 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
main.cpp: In function ‘int main(int, char**)’:
main.cpp:9:28: error: expected ‘;’ before ‘{’ token
jsonAuthenticate += " "{ "jsonrpc": "2.0", "id": 1, "method": "call", "params": [ "00000000000000000000000000000000", "session", "login", { "username": "root", "password": "********" } ] }"";
^
main.cpp:9:195: warning: statement has no effect [-Wunused-value]
": [ "00000000000000000000000000000000", "session", "login", { "username": "root", "password": "********" } ] }"";
^
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..
jsonAuthenticate = "curl -d";
jsonAuthenticate += " \"{ \"jsonrpc\": \"2.0\", \"id\": 1, \"method\": \"call\", \"params\": [ \"00000000000000000000000000000000\", \"session\", \"login\", { \"username\": \"root\", \"password\": \"********\" } ] }\" ";
jsonAuthenticate += " http://192.168.2.1/ubus ";
QString jsonAuthenticate;
jsonAuthenticate = "curl -d";
jsonAuthenticate += " \"{ \"jsonrpc\": \"2.0\", \"id\": 1, \"method\": \"call\", \"params\": [ \"00000000000000000000000000000000\", \"session\", \"login\", { \"username\": \"root\", \"password\": \"********\" } ] }\" ";
jsonAuthenticate += " http://192.168.2.1/ubus ";
To copy to clipboard, switch view to plain text mode
Bookmarks