JSON.Stringify
Good day!
I have a code that create JSON.
var a = 2
var user = {
userName:"admin",
password:"569123A6421D6D392C469CA683504E66",
clientType:"Web3.0",
realm:"Login to 90:02:a9:c4:2b:a3",
random:"Login to 90:02:a9:c4:2b:a3",
passwordType:"Dafault",
id:"2",
session:"a",
}
str = JSON.Stringify(user);
IR.Log(str);
expect to see in log - {"userName":"admin", "password":"569123A6421D6D392C469CA683504E66", "clientType":"Web3.0", "realm":"Login to 90:02:a9:c4:2b:a3", "random":"Login to 90:02:a9:c4:2b:a3", "passwordType":"Dafault", "id":"2", "session":2,
BUT i see - {"userName":"admin", "password":"569123A6421D6D392C469CA683504E66", "clientType":"Web3.0", "realm":"Login to 90:02:a9:c4:2b:a3", "passwordType":"Dafault", "id":"2", "session":2, "random":"Login to 90:02:a9:c4:2b:a3"}
Why order is broken?
Customer support service by UserEcho
You made an error in object creation. In any object you shouldn't add a comma after the last object item.
Please use any JS validator to be sure that you make everything right.
How it should be:
and result will be:
OK!.
Your script copied to iridium 1.0.5
[11-07-2016 22:01:44.906] INFO CORE *** The client started to work ***
Why so?
Hello!
For no obvious reason to us, when you convert the object to a string, the key with name "random" appears in different places. If you change this name to another, all the keys remain in their place. Tell me, how important are the order of the keys in the string, which is obtained after conversion?
Didi you understand why "random" appears in random places of json?