惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

云风的 BLOG
云风的 BLOG
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
IT之家
IT之家
Recent Announcements
Recent Announcements
B
Blog
D
Docker
V
V2EX
GbyAI
GbyAI
L
LangChain Blog
博客园 - Franky
U
Unit 42
T
The Blog of Author Tim Ferriss
A
About on SuperTechFans
博客园 - 【当耐特】
Google DeepMind News
Google DeepMind News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Vercel News
Vercel News
博客园_首页
D
DataBreaches.Net
人人都是产品经理
人人都是产品经理
Y
Y Combinator Blog
量子位
Blog — PlanetScale
Blog — PlanetScale
罗磊的独立博客

博客园 - 云飞扬IT

asp.net mvc 传参问题 在 ASP.NET Core 中使用 IHttpClientFactory 发出 HTTP 请求(官方文档) C# IConfiguration 注入 理解(AI) C# webapi 参数(AI) Error:(246, 5) error: resource android:attr/ttcIndex not found Android Gradle 插件版本与Gradle版本对应 flutter 水平Row示例 flutter Padding的用法 java 三个类名 abstract extends implements flutter Vs code 快速创建2个状态的快捷代码 flutter分号还是逗号 flutter在线站点 windows 10 安装 sql 2005 安装失败 开发和常用工具推荐清单 ---转 ASP.NET MVC+EF框架+EasyUI实现权限管理系列(24)-权限组的设计和实现(附源码) ---转 【商业源码】生日大放送-Newlife商业源码分享 -转 我个人所有的独立博客wordpress都被挂马 .NET Web开发技术简单整理 转 程序员常用不常见很难得的地址大全转
flutter解析json参考
云飞扬IT · 2020-06-27 · via 博客园 - 云飞扬IT

参考的2段代码 https://flutter.dev/docs/cookbook/networking/background-parsing

First, create a Photo class that contains data about a photo. Include a fromJson() factory method to make it easy to create a Photo starting with a JSON object.

class Photo {
  final int id;
  final String title;
  final String thumbnailUrl;

  Photo({this.id, this.title, this.thumbnailUrl});

  factory Photo.fromJson(Map<String, dynamic> json) {
    return Photo(
      id: json['id'] as int,
      title: json['title'] as String,
      thumbnailUrl: json['thumbnailUrl'] as String,
    );
  }
}

Convert the response into a list of photos

Now, use the following instructions to update the fetchPhotos() function so that it returns a Future<List<Photo>>:

  1. Create a parsePhotos() function that converts the response body into a List<Photo>.
  2. Use the parsePhotos() function in the fetchPhotos() function.
// A function that converts a response body into a List<Photo>.
List<Photo> parsePhotos(String responseBody) {
  final parsed = json.decode(responseBody).cast<Map<String, dynamic>>();

  return parsed.map<Photo>((json) => Photo.fromJson(json)).toList();
}

Future<List<Photo>> fetchPhotos(http.Client client) async {
  final response =
      await client.get('https://jsonplaceholder.typicode.com/photos');

  return parsePhotos(response.body);
}