Json array and qml
-
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!