Hello,
Please let me know how to create following string in control script. I would like to create following for sending information in JSON format:
string text= '{"name":"John Johnson","street":"Oslo West 16","phone":"555 1234567"}';
Best Regards,
Amit Golhani
double quotes in control scripts
- mpoint
- Posts:49
- Joined: Thu Oct 28, 2010 11:28 am
Re: double quotes in control scripts
You have to surround the whole string with double quotes, and then escape the double quotes inside it with backslashes.
string text = "{\\"name\\":\\"John Johnson\\",\\"street\\":\\"Oslo West 16\\",\\"phone\\":\\"555 1234567\\"}";
string text = "{\\"name\\":\\"John Johnson\\",\\"street\\":\\"Oslo West 16\\",\\"phone\\":\\"555 1234567\\"}";
- amitgolhani
- Posts:41
- Joined: Thu Apr 10, 2014 10:32 am
Re: double quotes in control scripts
I am getting folliwing response with backslashes:
WCCOAui1:["{\\"name\\":\\"John Johnson\\",\\"street\\":\\"Oslo West 16\\",\\"phone\\":\\"555 1234567\\"}"]
which is not correct as per JSON format.
WCCOAui1:["{\\"name\\":\\"John Johnson\\",\\"street\\":\\"Oslo West 16\\",\\"phone\\":\\"555 1234567\\"}"]
which is not correct as per JSON format.
- Gertjan van Schijndel
- Posts:634
- Joined: Mon Aug 02, 2010 10:37 am
Re: double quotes in control scripts
Perhaps the logviewer also adds escape characters. You should try it by writing the string on a panel or to a file.
- amitgolhani
- Posts:41
- Joined: Thu Apr 10, 2014 10:32 am
Re: double quotes in control scripts
Hi Gertjan,
You are correct. Logviewer is adding escape character. I tried to send string on socket and getting correct string. Thanks!
Best Regards,
Amit Golhani
You are correct. Logviewer is adding escape character. I tried to send string on socket and getting correct string. Thanks!
Best Regards,
Amit Golhani