JSON数据解析



我有来自API的JSON数据,我想按类解析它。但我有一个问题。在第一个视频中,问题等于零,但在另一个视频中,它不是零。我不知道如何解析它。

[{type: MAIN, video: {id: firstIdStr, url: firstURLStr, thumbnail: firstThumbmainURLStr, duration: 4363}, question: null}, {type: ANSWER_FOR_INTERVIEW, video: {id: secondIdStr, url: secondURLStr, thumbnail: secondThumbmainURLStr, duration: 4123}, question: {id:quiestioId, category:questionCategory, text:questionText}, {type: ANSWER_FOR_INTERVIEW, video: {id: thirdIdStr, url: thirdURLStr, thumbnail: thirdThumbmainURLStr, duration: 4123}, question: {id:quiestioId, category:questionCategory, text:questionText}}]

我终于找到答案

class Question {
Question({
this.category,
this.id,
this.text,
});
String category;
String id;
String text;
factory Question.fromJson(Map<String, dynamic> json) => json == null
? null
: Question(
category: json["category"],
id: json["id"],
text: json["text"],
);
Map<String, dynamic> toJson() => {
"category": category != null ? category : "",
"id": id != null ? id : "",
"text": text != null ? text : "",
};
}

最新更新