如何在Dart中处理JSON [英] How to handle JSON in Dart
本文介绍了如何在Dart中处理JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不知道Dart如何处理JSON?具体来说:
- 我可以存取JSON物件中的项目,以及何时,如何?
- 我将Darts数据结构(如Set和Maps)转换成JSON?
- 我可以创建一个新的JSON,只能通过调用JSON.parse?
你可能会发现这个帖子很有趣:
http://www.grobmeier.de/dart-creating-a-dynamic-list-with-dart-php-and-json-20112011.html
您需要使用JSON包(将json添加到pubspec.yaml):
import'package:json / json。镖';
以下是相应的规格:
https://api.dartlang.org/docs/channels/stable/latest/json.html p>
您的问题:
- 您可以使用:List result = JSON.parse jsonData);
- 使用stringify可以转换为例如一个Map为JSON
- 对不起,不确定这个问题。你可以做:JSON.parse('{key:value}'));
您可能需要使用parse从JSON创建一个Map,然后添加您的项目,然后调用stringify
I wonder how does Dart handle JSON? More specifically:
- Can I access item in a JSON object and when, how?
- Can I convert Darts data structures like Set and Maps into JSON?
- Can I create a new JSON, only by calling JSON.parse?
- How can I add new items into a JSON?
解决方案
You might find this post of mine interesting: http://www.grobmeier.de/dart-creating-a-dynamic-list-with-dart-php-and-json-20112011.html
You need to use the JSON package (add json to pubspec.yaml):
import 'package:json/json.dart';
Here is the according spec: https://api.dartlang.org/docs/channels/stable/latest/json.html
To your questions:
- You can use: List result = JSON.parse( jsonData );
- With stringify you can turn for example a Map to JSON
- I am sorry, not sure on this question. You could do: JSON.parse('{key:"value"}')); or something like that
- You probably need to create a Map out of your JSON with parse, then add your item, and then call stringify
这篇关于如何在Dart中处理JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文