JSON.stringify with non-alphabetical order

  • Hi,
    I try to use websockets with json and I got a problem:

    I make a json string with JSON.stringify(); but it's changing my object order
    Is there a possible way to change this

    what I do (in my QML):
    socket_api is a Websocket component (QML)

          This is what I call every time we need to send data
          Client -> Server
          note: use a debug pass/user pair here
        function requestAPI(func, args){
            var user_name = "admin"
            var user_password = "Hunter2"
            var userCredential = {username:user_name, password:user_password};
            var userCredentials_json = JSON.stringify(userCredential.toString());
            console.log("credentuals string: "+ userCredentials_json);
            var requestedArguments = {};
            var functionToRequest = { funcName: "pong", arguments: requestedArguments};
            var functionToRequest_json = JSON.stringify(functionToRequest);
            var myRequest = {credentials: userCredential, func:functionToRequest};
            var myRequest_json = JSON.stringify(myRequest);

    with this i get:

    qml: {"credentials":{"password":"Hunter2","username":"admin"},"func":{"arguments":{},"funcName":"pong"}}

    wich isn't original's order.

    Is there a way to fix that?

    Thanks in advance!

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.