Book Image

DART Cookbook

By : Ivo Balbaert
Book Image

DART Cookbook

By: Ivo Balbaert

Overview of this book

Table of Contents (18 chapters)
Dart Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using a JSON web service


In this recipe, we make a browser app ask data from a web service (Yahoo stock data) in JSON format, decode that data, and dynamically build up the web page showing the data.

Getting ready

This is what the URL we will use will look like: http://query.yahooapis.com/v1/public/yql?q=SELECT.

To get the data, we use the Yahoo Query Language (YQL), q= indicating the start of the query represented by SELECT. Suppose we want to look up stock data for Yahoo, Google, Apple, and Microsoft, the selected query will be of the following form:

select * from yahoo.finance.quotes where symbol in(YHOO,AAPL,GOOG,CMSFT) &env=http://datatables.org/Falltables.env&format=json

How to do it...

Look at the code in stockviewer_dart:

import 'dart:html';
import 'dart:convert';

main() {
  LoadData();
}
  1. Call the web server asynchronously using the following code:

    void LoadData() {
      var stock = "GOOG";
      var request = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance...