首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Dart编程查询:从GET读取响应

Dart编程查询:从GET读取响应
EN

Stack Overflow用户
提问于 2013-12-06 10:31:33
回答 2查看 272关注 0票数 1

假设我得到了一个请求URL = var url = "https://www.googleapis.com/books/v1/volumes?q=dart+java";

一击中它,我就会得到回应,类似于下面提到的一个。如果我想简单地列出这些标题的列表,我如何在Dart中做到这一点?

我想为输出标题中的每一本书显示作者发布的日期描述。

代码语言:javascript
复制
{
 "kind": "books#volumes",
 "totalItems": 1025,
 "items": [
  {
   "kind": "books#volume",
   "id": "ECGJMAEACAAJ",
   "etag": "jnz5pApZSnA",
   "selfLink": "https://www.googleapis.com/books/v1/volumes/ECGJMAEACAAJ",
   "volumeInfo": {
    "title": "Dart in Action",
    "authors": [
     "Chris Buckett"
    ],
    "publisher": "Manning Publications",
    "publishedDate": "2013",
    "description": "Summary Dart in Action introduces Google's Dart language and provides techniques and examples showing how to use it as a viable replacement for Java and JavaScript in browser-based desktop and mobile applications. It begins with a rapid overview of Dart language and tools, including features like interacting with the browser, optional typing, classes, libraries, and concurrency with isolates. After you master the core concepts, you'll move on to running Dart on the server and creating single page HTML5 web applications. About the Technology Dart is a web programming language developed by Google. It has modern OO features, just like Java or C#, while keeping JavaScript's dynamic and functional characteristics. Dart applications are \"transpiled\" to JavaScript, and they run natively in Dart-enabled browsers. With production-quality libraries and tools, Dart operates on both the client and the server for a consistent development process. About this Book Dart in Action introduces the Dart language and teaches you to use it in browser-based, desktop, and mobile applications. Not just a language tutorial, this book gets quickly into the nitty-gritty of using Dart. Most questions that pop up while you're reading are answered on the spot! OO newbies will appreciate the gentle pace in the early chapters. Later chapters take a test-first approach and encourage you to try Dart hands-on. To benefit from this book you'll need experience with HTML and JavaScript?a Java or C# background is helpful but not required. Purchase of the print book comes with an offer of a free PDF, ePub, and Kindle eBook from Manning. Also available is all code from the book. What's Inside Dart from the ground up Numerous code samples and diagrams Creating single-page web apps Transitioning from Java, C#, or JavaScript Running Dart in the browser and on the server About the Author Chris Buckett builds enterprise-scale web applications. He runs Dartwatch.com and is an active contributor to the dartlang list. \"Includes numerous examples of core language features as well as more advanced HTML5 features.\"—From the Foreword by Seth Ladd, Developer Advocate, Google Table of Contents PART 1 INTRODUCING DART Hello Dart \"Hello World\" with Dart tools Building and testing your own Dart app PART 2 CORE DART Functional first-class functions and closures Understanding libraries and privacy Constructing classes and interfaces Extending classes and interfaces Collections of richer classes Asynchronous programming with callbacks and futures PART 3 CLIENT-SIDE DART APPS Building a Dart web app Navigating offline data Communicating with other systems and languages PART 4 SERVER-SIDE DART Server interaction with files and HTTP Sending, syncing, and storing data Concurrency with isolates",
    "industryIdentifiers": [
     {
      "type": "ISBN_10",
      "identifier": "1617290866"
     },
     {
      "type": "ISBN_13",
      "identifier": "9781617290862"
     }
    ],
    "pageCount": 398,
    "printType": "BOOK",
    "categories": [
     "Computers"
    ],
    "averageRating": 3.0,
    "ratingsCount": 1,
    "contentVersion": "preview-1.0.0",
    "imageLinks": {
     "smallThumbnail": "http://bks9.books.google.co.in/books?id=ECGJMAEACAAJ&printsec=frontcover&img=1&zoom=5&source=gbs_api",
     "thumbnail": "http://bks9.books.google.co.in/books?id=ECGJMAEACAAJ&printsec=frontcover&img=1&zoom=1&source=gbs_api"
    },
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-12-06 11:01:55

你可以像

代码语言:javascript
复制
void main(List<String> x) {
  var js = '''
    ... some JSON ...
  ''';

  Map d = JSON.decode(js);

  var books = (d['items'] as List).forEach((Map item) {
    print('Title: ${item['volumeInfo']['title']}');
    if(item['volumeInfo']['authors'] != null) {
      (item['volumeInfo']['authors'] as List).forEach((a) => print('  Author: ${a}'));
    }
  });
}
票数 0
EN

Stack Overflow用户

发布于 2013-12-06 10:38:31

你可以:

代码语言:javascript
复制
import 'dart:html';
import 'dart:convert';

HttpRequest.getString('https://www.googleapis.com/books/v1/volumes?q=dart+java')
  .then((String fileContents) {
    // parse the content with JSON and do what you want...
    final json = JSON.decode(fileContents);
  })
  .catchError((Error error) {
    print(error.toString());
  });
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20421671

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档