double quotes in control scripts

Find and share HowTos to various installations / configurations!
5 posts • Page 1 of 1
amitgolhani
Posts:41
Joined: Thu Apr 10, 2014 10:32 am

double quotes in control scripts

Post by amitgolhani »

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

mpoint
Posts:49
Joined: Thu Oct 28, 2010 11:28 am

Re: double quotes in control scripts

Post by mpoint »

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\\"}";

amitgolhani
Posts:41
Joined: Thu Apr 10, 2014 10:32 am

Re: double quotes in control scripts

Post by amitgolhani »

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.

Gertjan van Schijndel
Posts:634
Joined: Mon Aug 02, 2010 10:37 am

Re: double quotes in control scripts

Post by Gertjan van Schijndel »

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

Post by amitgolhani »

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

5 posts • Page 1 of 1