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. How to access JSON web services from QML
Qt 6.11 is out! See what's new in the release blog

How to access JSON web services from QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 4 Posters 2.1k 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.
  • Q Offline
    Q Offline
    qtuser01
    wrote on last edited by
    #1

    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/webservice

    For example, this call:
    Http://www.radio-browser.info/webservice/json/stations/bytag/soul

    Until 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?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sandro4912
      wrote on last edited by
      #2

      For me this example is not even working anymore.

      It just gives:

      SyntaxError: JSON.parse: Parse error
      
      Christian EhrlicherC fcarneyF 2 Replies Last reply
      0
      • S sandro4912

        For me this example is not even working anymore.

        It just gives:

        SyntaxError: JSON.parse: Parse error
        
        Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @sandro4912 Do you really think this is important to know 3 years after the question was opened?

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        0
        • S sandro4912

          For me this example is not even working anymore.

          It just gives:

          SyntaxError: JSON.parse: Parse error
          
          fcarneyF Offline
          fcarneyF Offline
          fcarney
          wrote on last edited by
          #4

          @sandro4912
          Maybe this is a better resource.

          C++ is a perfectly valid school of magic.

          1 Reply Last reply
          0

          • Login

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