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 array and qml
QtWS25 Last Chance

Json array and qml

Scheduled Pinned Locked Moved QML and Qt Quick
1 Posts 1 Posters 1.7k Views
  • 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.
  • H Offline
    H Offline
    h1ddev
    wrote on last edited by
    #1

    Hi. I have a little problem. This is the Json:

    @{"therainman":{"id":166365,"name":"The Rain Man","profileIconId":642,"summonerLevel":30,"revisionDate":1394650685000}}@

    Is a example. The name "therainman" changes when i request another nickname. If i request therainman, the server send to me this json. If i request, for example, c9meteos, changes everything and they send me another thing.

    Now, this is the code:

    @ TextInput {
    id: textInput1
    x: 147
    y: 42
    width: 80
    height: 20
    text: qsTr("Text Input")
    font.pixelSize: 12
    focus: true
    Keys.onPressed: {
    if (event.key == Qt.Key_Return){

                    request(textInput1.text)
                    return
                }
            }
        }
    }
    
    function request(a) {
        var xhr = new XMLHttpRequest();
        xhr.onreadystatechange = function() {
            if (xhr.readyState === XMLHttpRequest.HEADERS_RECEIVED) {
                print('HEADERS_RECEIVED')
            } else if(xhr.readyState === XMLHttpRequest.DONE) {
                print('DONE');
                var obj = JSON.parse(xhr.responseText.toString());
                
    
                print(obj.a.id)
    
            }
        }
        xhr.open("GET", "https://prod.api.pvp.net/api/lol/na/v1.3/summoner/by-name/"+a+"?api_key=<api_key>");
        xhr.send();
    }@
    

    The problem is here:

    print(obj.a.id)

    This just not work. If i set print(obj.therainman.id), it works. But this is a value that changes to whatever i want in a textinput, so i can't put this. I don't know how to declare this.

    Thanks and sorry for my english!

    1 Reply Last reply
    1

    • Login

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