如何在 Flutter 中解码 JSON? [英] How to decode JSON in Flutter?

查看:26
本文介绍了如何在 Flutter 中解码 JSON?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Flutter 中解码 JSON?

How to decode JSON in Flutter?

问题很简单,但答案并不简单,至少对我来说是这样.

The question is simple, but the answer isn't, at least for me.

我有一个使用大量 JSON 字符串的项目.基本上,应用程序和服务器之间的整个通信都是通过 JSON 进行的.

I have a project that uses a lot of JSON Strings. Basically, the entire communication between the app and the server is through JSON.

我一直在使用 JSON.decode(json_string) 来处理它,但今天我更新了 Flutter 核心 (0.5.8-pre.178) 并且 JSON.decode 不再可用.

I have been using JSON.decode(json_string) to deal with it, but today I updated the Flutter core (0.5.8-pre.178) and JSON.decode isn't available anymore.

我去了 Flutter Docs 寻求帮助,但它仍然说要使用 JSON.decode.

I went to the Flutter Docs to seek help, but it still says to use JSON.decode.

那么,从现在开始如何在 Flutter 中解码 JSON?

So, how to decode JSON in Flutter from now on?

推荐答案

就用

json.decode()

jsonDecode()

在 Dart 2 中,所有尖叫大小写的常量都更改为小写字母.

In Dart 2 all screaming-case constants were changed to lower-camel-case.

确保import 'dart:convert';

这篇关于如何在 Flutter 中解码 JSON?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆