Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
颤振镖json未处理异常:InternalLinkedHashMap<;字符串,动态>';不是类型为';列表<;动态>;_Json_Rest_Http_Flutter_Dart - Fatal编程技术网

颤振镖json未处理异常:InternalLinkedHashMap<;字符串,动态>';不是类型为';列表<;动态>;

颤振镖json未处理异常:InternalLinkedHashMap<;字符串,动态>';不是类型为';列表<;动态>;,json,rest,http,flutter,dart,Json,Rest,Http,Flutter,Dart,我从另一个问题中得到了这个代码(感谢chunhunghan)。我需要做一个登录屏幕,我试图根据服务器返回给我的响应验证用户凭据,但每次我尝试运行代码时,它都会给我“未处理的异常:InternalLinkedHashMap”不是“List”类型错误的子类型,我不确定如何修复它 这就是模型: import 'dart:convert'; Payload payloadFromJson(String str) => Payload.fromJson(json.decode(str)); Str

我从另一个问题中得到了这个代码(感谢chunhunghan)。我需要做一个登录屏幕,我试图根据服务器返回给我的响应验证用户凭据,但每次我尝试运行代码时,它都会给我“未处理的异常:InternalLinkedHashMap”不是“List”类型错误的子类型,我不确定如何修复它

这就是模型:

import 'dart:convert';
Payload payloadFromJson(String str) => Payload.fromJson(json.decode(str));

String payloadToJson(Payload data) => json.encode(data.toJson());

class Payload {
  Payload({
    this.version,
    this.encoding,
    this.subsonicResponse,
  });

  String version;
  String encoding;
  SubsonicResponse subsonicResponse;

  factory Payload.fromJson(Map<String, dynamic> json) => Payload(
        version: json["version"],
        encoding: json["encoding"],
        subsonicResponse: SubsonicResponse.fromJson(json["subsonic-response"]),
      );

  Map<String, dynamic> toJson() => {
        "version": version,
        "encoding": encoding,
        "subsonic-response": subsonicResponse.toJson(),
      };
}

class SubsonicResponse {
  SubsonicResponse({
    this.status,
    this.version,
    this.xmlns,
    this.albumList,
  });

  String status;
  String version;
  String xmlns;
  AlbumList albumList;

  factory SubsonicResponse.fromJson(Map<String, dynamic> json) =>
      SubsonicResponse(
        status: json["status"],
        version: json["version"],
        albumList: AlbumList.fromJson(json["albumList"]),
      );

  Map<String, dynamic> toJson() => {
        "status": status,
        "version": version,
        "albumList": albumList.toJson(),
      };
}

class AlbumList {
  AlbumList({
    this.album,
  });

  List<AlbumsList> album;

  factory AlbumList.fromJson(Map<String, dynamic> json) => AlbumList(
        album: json["album"] == null ? null: List<AlbumsList>.from(json["album"].map((x) => AlbumsList.fromJson(x))),);

  Map<String, dynamic> toJson() => {
        "album": album == null ? null: List<dynamic>.from(album.map((x) => x.toJson())),
      };
}

class AlbumsList {
  AlbumsList({
    this.id,
    this.parent,
    this.isDir,
    this.title,
    this.album,
    this.artist,
    this.genre,
    this.coverArt,
    this.playCount,
    this.created,
    this.year,
  });

  String id;
  String parent;
  String isDir;
  String title;
  String album;
  String artist;
  String genre;
  String coverArt;
  String playCount;
  DateTime created;
  String year;

  factory AlbumsList.fromJson(Map<String, dynamic> json) => AlbumsList(
        id: json["id"],
        parent: json["parent"],
        isDir: json["isDir"],
        title: json["title"],
        album: json["album"],
        artist: json["artist"],
        genre: json["genre"],
        coverArt: json["coverArt"],
        playCount: json["playCount"],
        created: DateTime.parse(json["created"]),
        year: json["year"] == null ? null : json["year"],
      );

  Map<String, dynamic> toJson() => {
        "id": id,
        "parent": parent,
        "isDir": isDir,
        "title": title,
        "album": album,
        "artist": artist,
        "genre": genre,
        "coverArt": coverArt,
        "playCount": playCount,
        "created": created.toIso8601String(),
        "year": year == null ? null : year,
      };
}

这是api响应

payloadFromJson
更改为

Payload payloadFromJson (Map<String, dynamic>str) => Payload.fromJson(str);
Payload payloadFromJson(Mapstr)=>Payload.fromJson(str);
如果json包含键,则从json获取值

 factory SubsonicResponse.fromJson(Map<String, dynamic> json) =>
      SubsonicResponse(
        status: json["status"],
        version: json["version"],
        albumList: json.containsKey("albumList")? AlbumList.fromJson(json["albumList"]):null,
      );
factory.fromJson(映射json)=>
亚音速响应(
状态:json[“状态”],
版本:json[“版本”],
albumList:json.containsKey(“albumList”)?albumList.fromJson(json[“albumList”]):null,
);

将payloadFromJson更改为
有效载荷payloadFromJson(Mapstr)=>Payload.fromJson(str)
@Nidheesh刚刚尝试了这个方法,解决了这个错误,但由于某种原因,当我尝试打印对象时,它会显示null。你能发布json@Nidheesh是的,我用json数据更新了帖子。我如何将亚音速响应的状态与字符串进行比较?您可以在
string
Payload payloadFromJson (Map<String, dynamic>str) => Payload.fromJson(str);
 factory SubsonicResponse.fromJson(Map<String, dynamic> json) =>
      SubsonicResponse(
        status: json["status"],
        version: json["version"],
        albumList: json.containsKey("albumList")? AlbumList.fromJson(json["albumList"]):null,
      );