“Lista DART do JSON” Kod odpowiedzi

Lista DART do JSON

import 'dart:convert';

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

Lista obiektów do 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}
Powerful Polecat

Odpowiedzi podobne do “Lista DART do JSON”

Pytania podobne do “Lista DART do JSON”

Więcej pokrewnych odpowiedzi na “Lista DART do JSON” w Dart

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu