Unsolved How to access JSON web services from QML
-
Translated from Spanish with Google
I would like to know what is needed to access JSON web data, specifically to the API of
Community Radio Browser: http://www.radio-browser.info/webserviceFor example, this call:
Http://www.radio-browser.info/webservice/json/stations/bytag/soulUntil now I had the following example of access to the Flickr API of the book Qt 5 Cadaques (https://qmlbook.github.io/en/ch11/index.html#flickr-calls), but it does not work for other services:
import QtQuick 2.5
Rectangle {
width: 320
height: 480
ListView {
id: view
anchors.fill: parent
delegate: Thumbnail {
width: view.width
text: modelData.title
iconSource: modelData.media.m
}
}function request() { 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 json = JSON.parse(xhr.responseText.toString()) view.model = json.items } } xhr.open("GET", "http://api.flickr.com/services/feeds/photos_public.gne?format=json&nojsoncallback=1&tags=munich"); xhr.send(); } Component.onCompleted: { request() }
}
Does it depend on whether the JSON response returns a callback or not?
-
For me this example is not even working anymore.
It just gives:
SyntaxError: JSON.parse: Parse error
-
@sandro4912 Do you really think this is important to know 3 years after the question was opened?
-