? AddStringParam use " \" " and/or ' " '

For developers using the Construct 2 Javascript SDK

Post » Tue Jun 09, 2015 10:09 pm

It would be nice to be able to use ' " ' and/or " \" " at "AddStringParam" and other.

At moment i have to use for example:
str("{'name':'"&Reg_NameIN.Text&"','password':'"&SmartFoxServer.EncryptPassword(Reg_PassIN.Text)&"','mail':'"&Reg_MailIN.Text&"'}")
That's a little crazy to write. :lol:
And in plugin I need to String.replace() ' with " to make a valid json.
I also can String.replace() ' in construct directly, but that makes it not better...
I think this also help for other things as json.

Or did I miss other options?
Last edited by deathangel1479 on Wed Jun 10, 2015 8:32 am, edited 3 times in total.
Sorry for my bad english, but I really do my best! And use and check with Google Translator.
B
11
S
4
G
1
Posts: 158
Reputation: 1,328

Post » Wed Jun 10, 2015 7:03 am

Both of these things are the standard and nature of urls and json formatting.

Use url encoded characters
" = %22
\ = %2f

Jsons use single quotations for keys so it is a restricted character. You probably will need to continue doing some creative replacing here to bypass this limitation
B
32
S
7
G
2
Posts: 317
Reputation: 2,851

Post » Wed Jun 10, 2015 8:07 am

Thanks for reply, but for me it was actually about Constructs->AddStringParam with 'string', not about json.
I know my english is not very well... :?

Conversely, this will work for json, but construct dont accept:
str('{"name"":"'&Reg_NameIN.Text&'","password":"'&SmartFoxServer.EncryptPassword(Reg_PassIN.Text)&'","mail":"'&Reg_MailIN.Text&'"}')

Other example for same situation:
str('He said:"Hello".')
str("He said:\"Hello\".")
This wont work in Construct. Is working in JavaScript. Would be nice if Construct accept this.

Or do you mean something like:
"{%22name%22%22:%22"&Reg_NameIN.Text&"%22,%22password%22:%22"&
SmartFoxServer.EncryptPassword(Reg_PassIN.Text)&"%22,%22mail%22:%22"&Reg_MailIN.Text&"%22}"
I think that's even worse.
Sorry for my bad english, but I really do my best! And use and check with Google Translator.
B
11
S
4
G
1
Posts: 158
Reputation: 1,328

Post » Wed Jun 10, 2015 8:54 am

To put a " in construct you need to use ""
"He said ""hello""."
B
94
S
33
G
113
Posts: 5,353
Reputation: 73,267

Post » Wed Jun 10, 2015 9:15 am

WTF When I watch this, it dizzy me. :lol:
But it seems to work and will make it more simple.
So "" is like \".
Thank you much, for this information!

And with my new sprintf, status is now:
Tools.sprintf("{""name"":""{0}"",""password"":""{1}"",""mail"":""{2}""}",Reg_NameIN.Text,SmartFoxServer.EncryptPassword(Reg_PassIN.Text),Reg_MailIN.Text)
Much better, now it is readable and no .replace needed! :D

But I think furthermore, would be nice to be able to use. 'He said: "Hello".'
Sorry for my bad english, but I really do my best! And use and check with Google Translator.
B
11
S
4
G
1
Posts: 158
Reputation: 1,328

Post » Wed Jul 29, 2015 3:42 am

@Ashley , is there any chance we could have es6 template strings in the editor to avoid this kind of thing?
maybe for c3?
B
11
S
2
G
1
Posts: 202
Reputation: 1,580


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests