Исключение произошло. NoSuchMethodError (NoSuchMethodError: У класса 'String' нет метода экземпляра 'map' - PullRequest
0 голосов
/ 04 мая 2020

я получаю строковое значение "" из json для profilevisitirarr, но оно относится к типу списка в модальном классе, если у пользователя нет никаких vistors, оно выдает исключение, потому что значение, полученное из json, является строкой, но если у пользователей есть посетители json вернуть список, так что в то время он отлично работал, как справиться с этим. этот модальный класс -----

 import 'dart:convert';

MyDetails myDetailsFromJson(String str) => MyDetails.fromJson(json.decode(str));

String myDetailsToJson(MyDetails data) => json.encode(data.toJson());

class MyDetails {   String errstr;   int errcode;   List<Map<String, String>> user;   List<Imagearr> imagearr;   String intereststatus;   String favByCount;   String profilevisitors;   String interestreceived;   List<Profilevisitorsarr> profilevisitorsarr;   List<Map<String, String>> interestexpressedbyarr;   List<Map<String, String>> favouritedbyarr;   String newmsgcount;   String viewedbycount;   String param1;   String param2;   String param3;   String param4;

  MyDetails({
    this.errstr,
    this.errcode,
    this.user,
    this.imagearr,
    this.intereststatus,
    this.favByCount,
    this.profilevisitors,
    this.interestreceived,
    this.profilevisitorsarr,
    this.interestexpressedbyarr,
    this.favouritedbyarr,
    this.newmsgcount,
    this.viewedbycount,
    this.param1,
    this.param2,
    this.param3,
    this.param4,   });

  factory MyDetails.fromJson(Map<String, dynamic> json) {
    if (json["profilevisitorsarr"].isEmpty) {
      json["profilevisitorsarr"] == "0";
    }
    return MyDetails(
      errstr: json["errstr"] == null ? null : json["errstr"],
      errcode: json["errcode"] == null ? null : json["errcode"],
      user: json["user"] == null
          ? null
          : List<Map<String, String>>.from(json["user"].map((x) =>
              Map.from(x).map((k, v) => MapEntry<String, String>(k, v)))),
      imagearr: json["imagearr"] == null
          ? null
          : List<Imagearr>.from(
              json["imagearr"].map((x) => Imagearr.fromJson(x))),
      intereststatus:
          json["intereststatus"] == null ? null : json["intereststatus"],
      favByCount: json["favByCount"] == null ? null : json["favByCount"],
      profilevisitors:
          json["profilevisitors"] == null ? null : json["profilevisitors"],
      interestreceived:
          json["interestreceived"] == null ? null : json["interestreceived"],
      profilevisitorsarr: json["profilevisitorsarr"] == "0"
          ? ""
          : List<Profilevisitorsarr>.from(json["profilevisitorsarr"]
              .map((x) => Profilevisitorsarr.fromJson(x))),
      interestexpressedbyarr: json["interestexpressedbyarr"] == null
          ? null
          : List<Map<String, String>>.from(json["interestexpressedbyarr"].map(
              (x) => Map.from(x).map((k, v) =>
                  MapEntry<String, String>(k, v == null ? null : v)))),
      favouritedbyarr: json["favouritedbyarr"] == null
          ? null
          : List<Map<String, String>>.from(json["favouritedbyarr"].map((x) =>
              Map.from(x).map((k, v) =>
                  MapEntry<String, String>(k, v == null ? null : v)))),
      newmsgcount: json["newmsgcount"] == null ? null : json["newmsgcount"],
      viewedbycount:
          json["viewedbycount"] == null ? null : json["viewedbycount"],
      param1: json["param1"] == null ? null : json["param1"],
      param2: json["param2"] == null ? null : json["param2"],
      param3: json["param3"] == null ? null : json["param3"],
      param4: json["param4"] == null ? null : json["param4"],
    );   }   Map<String, dynamic> toJson() => {
        "errstr": errstr == null ? null : errstr,
        "errcode": errcode == null ? null : errcode,
        "user": user == null
            ? null
            : List<dynamic>.from(user.map((x) =>
                Map.from(x).map((k, v) => MapEntry<String, dynamic>(k, v)))),
        "imagearr": imagearr == null
            ? null
            : List<dynamic>.from(imagearr.map((x) => x.toJson())),
        "intereststatus": intereststatus == null ? null : intereststatus,
        "favByCount": favByCount == null ? null : favByCount,
        "profilevisitors": profilevisitors == null ? null : profilevisitors,
        "interestreceived": interestreceived == null ? null : interestreceived,
        "profilevisitorsarr": profilevisitorsarr == null
            ? null
            : List<dynamic>.from(profilevisitorsarr.map((x) => x.toJson())),
        "interestexpressedbyarr": interestexpressedbyarr == null
            ? null
            : List<dynamic>.from(interestexpressedbyarr.map((x) => Map.from(x)
                .map((k, v) =>
                    MapEntry<String, dynamic>(k, v == null ? null : v)))),
        "favouritedbyarr": favouritedbyarr == null
            ? null
            : List<dynamic>.from(favouritedbyarr.map((x) => Map.from(x).map(
                (k, v) => MapEntry<String, dynamic>(k, v == null ? null : v)))),
        "newmsgcount": newmsgcount == null ? null : newmsgcount,
        "viewedbycount": viewedbycount == null ? null : viewedbycount,
        "param1": param1 == null ? null : param1,
        "param2": param2 == null ? null : param2,
        "param3": param3 == null ? null : param3,
        "param4": param4 == null ? null : param4,
      }; }

class Imagearr {   String id;   String permissions;   String image;   String thumbnail;   String original;   String imagecount;   Params params;

  Imagearr({
    this.id,
    this.permissions,
    this.image,
    this.thumbnail,
    this.original,
    this.imagecount,
    this.params,   });

  factory Imagearr.fromJson(Map<String, dynamic> json) => Imagearr(
        id: json["id"] == null ? null : json["id"],
        permissions: json["permissions"] == null ? null : json["permissions"],
        image: json["image"] == null ? null : json["image"],
        thumbnail: json["thumbnail"] == null ? null : json["thumbnail"],
        original: json["original"] == null ? null : json["original"],
        imagecount: json["imagecount"] == null ? null : json["imagecount"],
        params: json["params"] == null ? null : Params.fromJson(json["params"]),
      );

  Map<String, dynamic> toJson() => {
        "id": id == null ? null : id,
        "permissions": permissions == null ? null : permissions,
        "image": image == null ? null : image,
        "thumbnail": thumbnail == null ? null : thumbnail,
        "original": original == null ? null : original,
        "imagecount": imagecount == null ? null : imagecount,
        "params": params == null ? null : params.toJson(),
      }; }

class Params {   String thumbnail;   DateTime lastupdated;   dynamic count;   int thumbnailId;

  Params({
    this.thumbnail,
    this.lastupdated,
    this.count,
    this.thumbnailId,   });

  factory Params.fromJson(Map<String, dynamic> json) => Params(
        thumbnail: json["thumbnail"] == null ? null : json["thumbnail"],
        lastupdated: json["lastupdated"] == null
            ? null
            : DateTime.parse(json["lastupdated"]),
        count: json["count"],
        thumbnailId: json["thumbnail_id"] == null ? null : json["thumbnail_id"],
      );

  Map<String, dynamic> toJson() => {
        "thumbnail": thumbnail == null ? null : thumbnail,
        "lastupdated":
            lastupdated == null ? null : lastupdated.toIso8601String(),
        "count": count,
        "thumbnail_id": thumbnailId == null ? null : thumbnailId,
      }; }

class Profilevisitorsarr {   String id;   String userid;   String viewedby;   DateTime viewdate;   String name;   String avatar;   String thumb;   String uAge;   String gender;

      Profilevisitorsarr({
    this.id,
    this.userid,
    this.viewedby,
       this.viewdate,
    this.name,
    this.avatar,
    this.thumb,
    this.uAge,
    this.gender,   });

  factory Profilevisitorsarr.fromJson(Map<String, dynamic> json) =>
      Profilevisitorsarr(
        id: json["id"] == null ? null : json["id"],
        userid: json["userid"] == null ? null : json["userid"],
        viewedby: json["viewedby"] == null ? null : json["viewedby"],
        viewdate:
            json["viewdate"] == null ? null : DateTime.parse(json["viewdate"]),
        name: json["name"] == null ? null : json["name"],
        avatar: json["avatar"] == null ? null : json["avatar"],
        thumb: json["thumb"] == null ? null : json["thumb"],
        uAge: json["uAge"] == null ? null : json["uAge"],
        gender: json["gender"] == null ? null : json["gender"],
      );

  Map<String, dynamic> toJson() => {
        "id": id == null ? null : id,
        "userid": userid == null ? null : userid,
        "viewedby": viewedby == null ? null : viewedby,
        "viewdate": viewdate == null ? null : viewdate.toIso8601String(),
        "name": name == null ? null : name,
        "avatar": avatar == null ? null : avatar,
        "thumb": thumb == null ? null : thumb,
        "uAge": uAge == null ? null : uAge,
        "gender": gender == null ? null : gender,
      };
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...