Search
 
SCRIPT & CODE EXAMPLE
 

DART

dart list to json

import 'dart:convert';

main() {
  List<String> tags = ['tagA', 'tagB', 'tagC'];
  String jsonTags = jsonEncode(tags);
  print(jsonTags);      // ["tagA","tagB","tagC"]
}
Comment

dart list of objects to json

class User {
  String name;
  int age;
  User(this.name, this.age);
  Map toJson() => { // You must create this toJson() method else you will get an error
        'name': name,
        'age': age,
      };
}


//Now in your main fucntion, use jsonEncode
import 'dart:convert';
main() {
  User user = User('Shristi Gautam', 25);
  String jsonUser = jsonEncode(user);
  print(jsonUser);
}

The result will be something like {"name":"Shristi Gautam","age":25}
Comment

PREVIOUS NEXT
Code Example
Dart :: dart string equals 
Dart :: flutter getx state management 
Dart :: flutter get child widget size 
Dart :: how to create space between list on flutter 
Dart :: callback with arguments flutter 
Dart :: flutter login pop to index 1 
Dart :: tooltip flutter 
Dart :: title in app bar from start flutter 
Dart :: arrary where dart 
Dart :: flutter navigator get result 
Dart :: flutter cupertino theme 
Dart :: tab color in flutter 
Dart :: flutter gesturedetector space also clickable 
Dart :: how to convert string into integer in flutter 
Dart :: flutter column stackov 
Dart :: how to remove listtile long pressflutter 
Dart :: dart list get by index 
Swift :: on swipe get contentoffset swift collectionview 
Swift :: Detect if device is ipad or iphone swift 
Swift :: Unique device id ios swift 
Swift :: swift xcode debug cannot see code backtrace 
Swift :: textfield style swiftui own 
Swift :: array length swift 
Swift :: swiftui scrollview hide scrollbar 
Swift :: swiftui full screen sheet 
Swift :: unit testing swift ui 
Swift :: porsche 
Swift :: Delete Realm database swift 
Swift :: standard bank swift code 
Swift :: dismiss keyboard on tap outside swiftui 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =