2

Is there a simple way to parse a JSON with TAU library? I couldn't find any solution.

I'm trying to get data from alphavantage api and display it: www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=MSFT&apikey=demo

I've tried XMLhttprequest and Jquery and none seems to work with Tizen Web App.

George Z.
  • 6,643
  • 4
  • 27
  • 47
grc
  • 304
  • 1
  • 5
  • 21

2 Answers2

3

To access external resources You need to add internet privilege and define access origin (both in config.xml):

<tizen:privilege name="http://tizen.org/privilege/internet"/>

and

<access origin="https://www.alphavantage.co" subdomains="true"/>

then You can simply get data with Fetch API:

fetch('https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=MSFT&apikey=demo')
    .then(res => res.json())
    .then(jsonData => { console.log(jsonData) });
Patryk Falba
  • 417
  • 3
  • 15
0

After setting up the config.xml as recommended above by @Patryk Falba,

I've come up with two working options:

Using fecth()

if (self.fetch) {
  console.log("Fetching...")
  fetch('https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=MSFT&apikey=demo')
    .then(response => response.json())
    .then(data => {
      console.log(data['Global Quote']['01. symbol'])
    })

} else {
  console.log("Something went wrong...")
}

Using XMLHttpRequest()

var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {

  if (this.readyState == 4 && this.status == 200) {
    var myObj = JSON.parse(this.responseText);
    console.log("Ok!");
    console.log(myObj['Global Quote']['01. symbol']);
  }
};

xmlhttp.open('GET', 'https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=MSFT&apikey=demo', true);
xmlhttp.send();
grc
  • 304
  • 1
  • 5
  • 21