Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. JSON.stringify with non-alphabetical order
Forum Updated to NodeBB v4.3 + New Features

JSON.stringify with non-alphabetical order

Scheduled Pinned Locked Moved Solved QML and Qt Quick
1 Posts 1 Posters 670 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on 20 Oct 2017, 18:51 last edited by
    #1

    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);
    
            console.log(myRequest_json)
            socket_api.sendTextMessage(myRequest_json);
        }
    

    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!

    1 Reply Last reply
    0

    1/1

    20 Oct 2017, 18:51

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved