引用

mport 'dart:convert';

JSON

解码(JSON String->Object)
// NOTE: Be sure to use double quotes ("),
// not single quotes ('), inside the JSON string.
// This string is JSON, not Dart.
var jsonString = '''
[
{"score": },
{"score": }
]
'''; var scores = jsonDecode(jsonString);
assert(scores is List); var firstScore = scores[];
assert(firstScore is Map);
assert(firstScore['score'] == );
编码(Object->JSON String)

支持int, double, String, bool, null, List, Map (with string keys)

var scores = [
{'score': },
{'score': },
{'score': , 'overtime': true, 'special_guest': null}
]; var jsonText = jsonEncode(scores);
assert(jsonText ==
'[{"score":40},{"score":80},'
'{"score":100,"overtime":true,'
'"special_guest":null}]');

UTF-8

解码
List<int> utf8Bytes = [
0xc3, 0x8e, 0xc3, 0xb1, 0xc5, 0xa3, 0xc3, 0xa9,
0x72, 0xc3, 0xb1, 0xc3, 0xa5, 0xc5, 0xa3, 0xc3,
0xae, 0xc3, 0xb6, 0xc3, 0xb1, 0xc3, 0xa5, 0xc4,
0xbc, 0xc3, 0xae, 0xc5, 0xbe, 0xc3, 0xa5, 0xc5,
0xa3, 0xc3, 0xae, 0xe1, 0xbb, 0x9d, 0xc3, 0xb1
]; var funnyWord = utf8.decode(utf8Bytes); assert(funnyWord == 'Îñţérñåţîöñåļîžåţîờñ');
解码stream
var lines = inputStream
.transform(utf8.decoder)
.transform(LineSplitter());
try {
await for (var line in lines) {
print('Got ${line.length} characters from stream');
}
print('file is now closed');
} catch (e) {
print(e);
}
编码
List<int> encoded = utf8.encode('Îñţérñåţîöñåļîžåţîờñ');

assert(encoded.length == utf8Bytes.length);
for (int i = ; i < encoded.length; i++) {
assert(encoded[i] == utf8Bytes[i]);
}

Flutter dart:convert的更多相关文章

  1. [flutter+dart] windows7下开发环境的安装与配置

    前言 博主是做嵌入式的,参加工作时间也不久,而且是非科班出身,之前从未接触过移动开发.最近了解到了flutter框架和dart语言,想作为第二语言学习一下,因此会从最基础的环节开始,以此博客作为记录, ...

  2. Android Gradle Issue - Flutter / Dart

    解决 "Minimum supported Gradle version is 4.6. Current version is 3.3." I have a problem wit ...

  3. Flutter & Dart

    Flutter & Dart https://www.dartlang.org/install https://flutter.dev/ https://flutter.dev/docs/ge ...

  4. 【Flutter 1-2】在 Windows 10下安装Flutter+Dart+Android Studio 配置Flutter开发环境

    在 Windows 10下安装Flutter+Dart+Android Studio 配置Flutter开发环境 文章首发地址 配置环境变量 由于部分网站被墙的原因,我们需要先配置Flutter国内镜 ...

  5. flutter & dart & vs code & bug

    flutter & dart & vs code & bug Waiting for another flutter command to release the startu ...

  6. Flutter & Dart 安装在window系统

    一.系统环境 flutter最低要求 1,windows7 SP1 64位版本以上,我的系统就是windows 7 sp1 64bit 2,git for windows ,没有安装的需要到这里下载  ...

  7. Flutter Dart中的异步

    以下内容从官网得到: https://webdev.dartlang.org/articles/performance/event-loop Even-Looper Dart是单线程模型,也就没有了所 ...

  8. Flutter——Dart Extension扩展方法的使用

    dart的extension方法可以给已经存在的类添加新的函数,通过extension我们可以封装一些常用方法,提高开发效率. 例一:扩展String 给string添加一个log打印方法 exten ...

  9. Flutter Dart List.map() 获取下标

    class HomePageState extends State{ final topTitles = ['审批单', '机票列表', '客服']; final topIcons = ['asset ...

随机推荐

  1. Java DB 访问(三)mybatis mapper interface接口

    1 项目说明 项目采用 maven 组织 ,依赖 mysql-connector-java,org.mybatis,junit pom 依赖如下: mysql 数据连接 : mysql-connect ...

  2. 8 Ways to Become a Better Coder

    It’s time to get serious about improving your programming skills. Let’s do it! That’s an easy career ...

  3. 剑指offer十七姊妹篇之二叉树的创建、遍历、判断子二叉树

    1.二叉树节点类 public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public Tr ...

  4. Linux 各种运算符

    目录 - 算术运算符 - 关系运算符 - 逻辑运算符 - 按位运算符 - 文件测试符 - 算术运算符 算术运算符,常用的有+.-.*./.%.++.--.** + - 加法运算符 [root@www ...

  5. Visual Studio最好用的快捷键(你最喜欢哪个)

    每次在网上搜关于VS有哪些常用快捷键的时候,出来的永远是一串长的不能再长的列表,完全没体现出“常用”二字,每次看完前面几个就看不下去了,相信大家都 有这种感觉.其实我们平时用的真的只有很少的一部分,借 ...

  6. 面试题----C语言中exit和return的区别

    C语言中return和exit的区别 exit用于结束进程,返回的状态码是给操作系统使用或父进程使用的.return是堆栈返回,返回的值是给主调函数用的.主线程结束前会默认调用exit结束进程. ex ...

  7. 【IT笔试面试题整理】连续子数组的最大和

    [试题描述]输入一个整型数组,数组里有正数也有负数.数组中一个或连续的多个整数组成一个子数组. 求所有子数组的和的最大值.要求时间复杂度O(n). 思路:当我们加上一个正数时,和会增加:当我们加上一个 ...

  8. mysql索引总结(1)-mysql 索引类型以及创建

    mysql索引总结(1)-mysql 索引类型以及创建 mysql索引总结(2)-MySQL聚簇索引和非聚簇索引 mysql索引总结(3)-MySQL聚簇索引和非聚簇索引 mysql索引总结(4)-M ...

  9. superset----缓存之redis

    一.概述 Superset使用Flask-Cache进行缓存,Flask-Cache支持redis,memcached,simplecache(内存),或本地文件系统)等缓存后端,如果你打算使用mem ...

  10. 精读JavaScript模式(二)

    我在想知识点怎么去分类,原本计划一章节一篇,但这样会会显得长短不一.更主要的是看到哪写的哪更为随意.那么这一篇还是紧接第一篇进行知识梳理,上篇说到了更优化的for循环,现在继续聊聊其它的循环方式. 1 ...