Results 1 to 2 of 2

Thread: How to get a Json value from an api and display it in a GUI

  1. #1
    Join Date
    Jun 2018
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default How to get a Json value from an api and display it in a GUI

    Good day,

    I'm tring to make a GUI that processes an api requested value. Those values are in Json format.

    https://api.bitmart.com/ticker/BMX_ETH

    Let's say I want to get the value of "bid_1" and make a pushbutton and a lable that changes into the value of "bid_1" when clicked.

    To make a simple onpushbuttonclicked I use this

    Qt Code:
    1. void MainWindow::on_pushButton_clicked()
    2. {
    3. ui->label_11->setText("Hello");
    4. }
    To copy to clipboard, switch view to plain text mode 
    Instead of "hello" I want a String with the value of "bid_1".

    As far as I understand I have to use

    Qt Code:
    1. void MainWindow::on_pushButton_clicked()
    2. {
    3. QUrl url("https://api.bitmart.com/ticker/BMX_ETH");
    4. QNetworkRequest request(url);
    5. //send request
    6. //read replied data
    7. //interpret replied data as string/Json
    8. ui->label->setText(QString::number);
    9. }
    To copy to clipboard, switch view to plain text mode 
    But I don't understand and would like to know how to send the request for a specific json value and convert it into a string.

    In Python you can just use this.

    Qt Code:
    1. def funkction():
    2. bid_data = requests.get("https://api.bitmart.com/ticker/BMX_ETH")
    3. return bid_data.json()["bid_1"]
    4.  
    5. value = float(function())
    To copy to clipboard, switch view to plain text mode 
    I'm looking for something simple like that since I'm not that skilled and appreciate any solution with the given example so I can transfer it to my project.

  2. #2
    Join Date
    Jan 2017
    Posts
    58
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to get a Json value from an api and display it in a GUI

    I have not worked with JSON, but this might help http://doc.qt.io/qt-5/json.html

Similar Threads

  1. JSon Problem
    By romzxlat in forum Newbie
    Replies: 5
    Last Post: 4th March 2015, 01:14
  2. What should be faster: csv, json or xml?
    By Momergil in forum Qt Programming
    Replies: 3
    Last Post: 9th March 2014, 21:14
  3. json
    By nabeel in forum Newbie
    Replies: 3
    Last Post: 29th August 2013, 09:24
  4. Qt and JSON
    By Chiggins in forum Qt Programming
    Replies: 2
    Last Post: 28th June 2010, 14:12

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.