Problem with JSon

I'm not getting concatenate the variables to make an acceptable result for json, can someone give me an idea of ​​the correct form of concatenation?

I'm doing this:

date: '{"sUserName": "' + nomeUser'","' + + '" sPassword ":"' + password +'"}',

and the result is as follows:

{"sUserName": "a", "" sPassword ":" a "}

Upvotes: -1

Views: 50

Answers (1)

Joe
Joe

Reputation: 82594

Replace:

'{"sUserName": "' + nomeUser'","' + + '" sPassword ":"' + password +'"}'

with

'{"sUserName": "' + nomeUser + '","' + 'sPassword":"' + password +'"}'

You have an extra '+' and an extra ". And here's a simple way to avoid this in the future:

var obj = {}; obj.sPassword = 'test'; obj.sUserName = 'p'; JSON.stringify(obj)

Upvotes: 3

Related Questions