“JSON do String Dart” Kod odpowiedzi

JSON do String Dart

import 'dart:convert';
main() {
  String objText = '{"name": "bezkoder", "age": 30}';
  User user = User.fromJson(jsonDecode(objText));
  print(user);
Mashood Hussain

Konwertuj JSON na DART

class TrendingMoviesModel {
  String? name;
  String? backdropPath;
  List<int>? genreIds;
  String? originalLanguage;
  String? posterPath;
  List<String>? originCountry;
  String? overview;
  String? mediaType;

  TrendingMoviesModel(
      {this.name,
      this.backdropPath,
      this.genreIds,
      this.originalLanguage,
      this.posterPath,
      this.originCountry,
      this.overview,
      this.mediaType});

  TrendingMoviesModel.fromJson(Map<String, dynamic> json) {
    name = json['name'];
    backdropPath = json['backdrop_path'];
    genreIds = json['genre_ids'].cast<int>();
    originalLanguage = json['original_language'];
    posterPath = json['poster_path'];
    originCountry = json['origin_country'].cast<String>();
    overview = json['overview'];
    mediaType = json['media_type'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['name'] = this.name;
    data['backdrop_path'] = this.backdropPath;
    data['genre_ids'] = this.genreIds;
    data['original_language'] = this.originalLanguage;
    data['poster_path'] = this.posterPath;
    data['origin_country'] = this.originCountry;
    data['overview'] = this.overview;
    data['media_type'] = this.mediaType;
    return data;
  }
}
Itchy Iguana

Odpowiedzi podobne do “JSON do String Dart”

Pytania podobne do “JSON do String Dart”

Więcej pokrewnych odpowiedzi na “JSON do String Dart” w JavaScript

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

Przeglądaj inne języki kodu