I have a postman API call. but I don't know how to extract data from the app JSON value in the API call of postman API. Can somebody clarify me about the how to extract it in dart data model.
{
"deviceType": "andriod",
"deviceId": "C6179909526098",
"deviceName": "Samsung-MT200",
"deviceOSVersion": "2.3.6",
"deviceIPAddress": "11.433.445.66",
"lat": 9.9312,
"long": 76.2673,
"buyer_gcmid": "",
"buyer_pemid": "",
"app": {
"version": "1.20.5",
"installTimeStamp": "2022-02-10T12:33:30.696Z",
"uninstallTimeStamp": "2022-02-10T12:33:30.696Z",
"downloadTimeStamp": "2022-02-10T12:33:30.696Z"
}
}
this is the data model.
class SplashPost {
String? deviceType;
String? deviceId;
String? deviceName;
String? deviceOSVerion;
String? deviceIPAddress;
String? lat;
String? long;
String? buyer_gcmid;
String? buyer_pemid;
String? version;
List<dynamic>? app;
SplashPost({
required this.deviceType,
required this.deviceIPAddress,
required this.deviceId,
required this.deviceName,
required this.deviceOSVerion,
required this.app,
required this.buyer_gcmid,
required this.buyer_pemid,
required this.lat,
required this.long,
required this.version,
});
factory SplashPost.fromJson(Map<String, dynamic> json) => SplashPost(
deviceIPAddress: json["deviceIPAddress"],
deviceType: json["deviceType"],
deviceId: json["deviceId"],
deviceName: json["deviceName"],
deviceOSVerion: json["deviceOSVersion"],
lat: json["lat"],
long: json["long"],
version: json["version"],
buyer_gcmid: json["buyer_gcmid"],
buyer_pemid: json["buyer_pemid"],
app: List<dynamic>.from(json["app"]).map((x) => x),
);
}
Map<String, dynamic> toJson() => {
"version": version,
"installTimeStamp": installTimeStamp,
"uninstallTimeStamp": uninstallTimeStamp,
"downloadTimeStamp": downloadTimeStamp,
};
This is the data model file and I don't know how to extract data from the "app" JSON value. It throws me the error of
The argument type 'Iterable' can't be assigned to the parameter type 'List?' in the list of app value.
and
Undefined name 'version'
Can somebody explain and solve my problem.
Personally I like using the website https://app.quicktype.io/ to generate a class from a response. It has some settings to tweak it to your liking and you can of course make adjustments yourself manually if the settings doesn't cover it. Here is an example output from that website, using your response.