JSON encode list string flutter

How to encode/decode JSON in Flutter

Last updated on October 30, 2020 A Goodman Loading... Loading... Post a comment

Dart

Show

( 52 Articles)

JSON encode list string flutter
How to create a Filter/Search ListView in Flutter (2021)

October 6, 2021

JSON encode list string flutter
Flutter: ListTile examples

July 29, 2021

JSON encode list string flutter
Sorting Lists in Dart and Flutter (5 Examples)

May 21, 2021

JSON encode list string flutter
Working with ElevatedButton in Flutter (2021)

October 6, 2021

JSON encode list string flutter
Customize Borders of TextField/TextFormField in Flutter

April 1, 2021

JSON encode list string flutter
How to check Type of a Variable in Flutter

November 3, 2020

JSON encode list string flutter
Flutter: Add a Search Field to an App Bar (2 Approaches)

August 10, 2021

JSON encode list string flutter
Most Popular Packages for State Management in Flutter (2021)

October 29, 2021

More

JSON encode list string flutter
report this ad

This article shows you how to encode/decode JSON in Flutter.

1. Import the dart:convert library:Advertisements

import 'dart:convert';

2. Use:

  • json.encode() or jsonEncode() for encoding
  • json.decode() or jsonDecode() for decoding

Examples

Example 1: JSON Encoding

final products = [ { 'id': 1, 'name': 'Product #1' }, { 'id': 2, 'name': 'Product #2' } ]; print(json.encode(products));

Output:

[{"id":1,"name":"Product #1"},{"id":2,"name":"Product #2"}]

Example 2: JSON decoding

final String responseData = '[{"id":1,"name":"Product #1"},{"id":2,"name":"Product #2"}]'; final products = json.decode(responseData); // Print the name of the second product in the list print(products[1]['name']);

Output:

Product #2

Hope this helps

Share Tweet Telegram
Subscribe
Notify of
I allow to use my email address and send notification about new comments and replies (you can unsubscribe at any time).
Label
{} [+]
Name*
Email*
Label
{} [+]
Name*
Email*
0 Comments
Inline Feedbacks
View all comments

Related Articles

JSON encode list string flutter
Flutter & Dart: 3 Ways to Generate Random Strings

November 24, 2021

JSON encode list string flutter
Flutter & Dart: Displaying Large Numbers with Digit Grouping

November 7, 2021

JSON encode list string flutter
Flutter: Avoid `print` calls in production code

October 29, 2021

JSON encode list string flutter
Flutter: Create a Password Strength Checker from Scratch

October 22, 2021

JSON encode list string flutter
Flutter: How to Draw a Heart with CustomPaint

October 14, 2021

JSON encode list string flutter
Implementing Tooltips in Flutter

October 11, 2021

JSON encode list string flutter
Flutter: Drawing an N-Pointed Star with CustomClipper

October 11, 2021

JSON encode list string flutter
Adding a Border to Text in Flutter

October 4, 2021

JSON encode list string flutter
Flutter: Stream.periodic example

October 4, 2021

JSON encode list string flutter
Using Static Methods in Dart and Flutter

October 1, 2021

JSON encode list string flutter
Flutter: DropdownButton Example

September 22, 2021

JSON encode list string flutter
Flutter: ExpansionPanelList and ExpansionPanelList.radio examples

September 21, 2021