将您的 JSON 字符串粘贴到 https://app.quicktype.io/,它将验证您的 JSON 字符串并转换为您需要的类。
示例学生 JSON 字符串
[
{
"ID": "1",
"Name": "Senpai",
"Gender": "1",
"Class": "32",
"Seat": "15",
"Club": "0",
"Persona": "1",
"Crush": "0",
"BreastSize": "0",
"Strength": "0",
"Hairstyle": "1",
"Color": "Black",
"Eyes": "Black",
"EyeType": "Default",
"Stockings": "None",
"Accessory": "0",
"ScheduleTime": "7_7_8_13.01_13.375_15.5_16_17.25_99_99",
"ScheduleDestination": "Spawn_Locker_Hangout_Seat_LunchSpot_Seat_Clean_Hangout_Locker_Exit",
"ScheduleAction": "Stand_Stand_Read_Sit_Eat_Sit_Clean_Read_Shoes_Stand",
"Info": "An average student. \n \n Average grades, average looks, average life... \n \n I'm not sure what you see in him."
},
{
"ID": "2",
"Name": "Yui Rio",
"Gender": "0",
"Class": "11",
"Seat": "14",
"Club": "1",
"Persona": "5",
"Crush": "0",
"BreastSize": "0.5",
"Strength": "0",
"Hairstyle": "2",
"Color": "Red",
"Eyes": "Red",
"EyeType": "Default",
"Stockings": "Red",
"Accessory": "0",
"ScheduleTime": "7_7_8_13_13.375_15.5_16_17.25_99_99",
"ScheduleDestination": "Spawn_Locker_Hangout_Seat_LunchSpot_Seat_Clean_Club_Locker_Exit",
"ScheduleAction": "Stand_Stand_Socialize_Sit_Socialize_Sit_Clean_SocialSit_Shoes_Stand",
"Info": ""
}
]
和解析这个例子的代码
// To parse this JSON data, do
//
// final payload = payloadFromJson(jsonString);
import 'dart:convert';
List<Payload> payloadFromJson(String str) => new List<Payload>.from(json.decode(str).map((x) => Payload.fromJson(x)));
String payloadToJson(List<Payload> data) => json.encode(new List<dynamic>.from(data.map((x) => x.toJson())));
class Payload {
String id;
String name;
String gender;
String payloadClass;
String seat;
String club;
String persona;
String crush;
String breastSize;
String strength;
String hairstyle;
String color;
String eyes;
String eyeType;
String stockings;
String accessory;
String scheduleTime;
String scheduleDestination;
String scheduleAction;
String info;
Payload({
this.id,
this.name,
this.gender,
this.payloadClass,
this.seat,
this.club,
this.persona,
this.crush,
this.breastSize,
this.strength,
this.hairstyle,
this.color,
this.eyes,
this.eyeType,
this.stockings,
this.accessory,
this.scheduleTime,
this.scheduleDestination,
this.scheduleAction,
this.info,
});
factory Payload.fromJson(Map<String, dynamic> json) => new Payload(
id: json["ID"],
name: json["Name"],
gender: json["Gender"],
payloadClass: json["Class"],
seat: json["Seat"],
club: json["Club"],
persona: json["Persona"],
crush: json["Crush"],
breastSize: json["BreastSize"],
strength: json["Strength"],
hairstyle: json["Hairstyle"],
color: json["Color"],
eyes: json["Eyes"],
eyeType: json["EyeType"],
stockings: json["Stockings"],
accessory: json["Accessory"],
scheduleTime: json["ScheduleTime"],
scheduleDestination: json["ScheduleDestination"],
scheduleAction: json["ScheduleAction"],
info: json["Info"],
);
Map<String, dynamic> toJson() => {
"ID": id,
"Name": name,
"Gender": gender,
"Class": payloadClass,
"Seat": seat,
"Club": club,
"Persona": persona,
"Crush": crush,
"BreastSize": breastSize,
"Strength": strength,
"Hairstyle": hairstyle,
"Color": color,
"Eyes": eyes,
"EyeType": eyeType,
"Stockings": stockings,
"Accessory": accessory,
"ScheduleTime": scheduleTime,
"ScheduleDestination": scheduleDestination,
"ScheduleAction": scheduleAction,
"Info": info,
};
}
关于您的 JSON 字符串,您可以使用以下内容对其进行解析
// To parse this JSON data, do
//
// final payload = payloadFromJson(jsonString);
import 'dart:convert';
Payload payloadFromJson(String str) => Payload.fromJson(json.decode(str));
String payloadToJson(Payload data) => json.encode(data.toJson());
class Payload {
The12341 the12341;
Payload({
this.the12341,
});
factory Payload.fromJson(Map<String, dynamic> json) => new Payload(
the12341: The12341.fromJson(json["12341"]),
);
Map<String, dynamic> toJson() => {
"12341": the12341.toJson(),
};
}
class The12341 {
The2014 the2014;
The12341({
this.the2014,
});
factory The12341.fromJson(Map<String, dynamic> json) => new The12341(
the2014: The2014.fromJson(json["2014"]),
);
Map<String, dynamic> toJson() => {
"2014": the2014.toJson(),
};
}
class The2014 {
The11 the11;
The2014({
this.the11,
});
factory The2014.fromJson(Map<String, dynamic> json) => new The2014(
the11: The11.fromJson(json["11"]),
);
Map<String, dynamic> toJson() => {
"11": the11.toJson(),
};
}
class The11 {
The21 the21;
The11({
this.the21,
});
factory The11.fromJson(Map<String, dynamic> json) => new The11(
the21: The21.fromJson(json["21"]),
);
Map<String, dynamic> toJson() => {
"21": the21.toJson(),
};
}
class The21 {
String the21Class;
String name;
The21({
this.the21Class,
this.name,
});
factory The21.fromJson(Map<String, dynamic> json) => new The21(
the21Class: json["class"],
name: json["name"],
);
Map<String, dynamic> toJson() => {
"class": the21Class,
"name": name,
};
}