我想使用 for 循环,我需要“photoThumbnailImagePath”数组,但我无法处理它...!我正在尝试获取图像路径的数组索引,但我只得到一张图像.....!我的价值不是印刷!我给了你我的代码和我的 json 数据......!请告诉我它是如何工作的,我应该如何打印我的图像值
if (response.statusCode == 200) {
var jsonResponse = json.decode(response.body);
print("laavvvvvvvvv :" + jsonResponse.toString());
var azim = List<FolderList>.from(jsonResponse["FolderList"].map((x) => FolderList.fromJson(x)));
// ignore: unnecessary_statements
print("printing");
for (final cam in azim){
print("photoThumbnailImagePath:" + cam.photoList[0].photoThumbnailImagePath.toString()); //i am getting here first image only i want all alisting array how
Photlistinng = [cam.photoList[0].photoThumbnailImagePath];
print("Photlistinng : " + Photlistinng.toString());
};
return AllPhotoListing.fromJson(json.decode(response.body));
} else {
// If the server did not return a 201 CREATED response,
// then throw an exception.
throw Exception('Failed to load data');
}
这是我的代码,当 api 成功然后我使用 for 循环但我的代码有问题所以请检查
这是我的 json 数据转换器
import 'dart:convert';
AllPhotoListing allPhotoListingFromJson(String str) => AllPhotoListing.fromJson(json.decode(str));
String allPhotoListingToJson(AllPhotoListing data) => json.encode(data.toJson());
class AllPhotoListing {
AllPhotoListing({
this.successCode,
this.successMessage,
this.totalPhotos,
this.totalLikes,
this.totalComments,
this.totalShared,
this.totalSelectedPhotosForAlbum,
this.watermarkType,
this.watermarkLogo,
this.watermarkText,
this.watermarkFont,
this.watermarkFontColor,
this.watermarkScaleHeight,
this.watermarkScaleWidth,
this.watermarkOpacity,
this.watermarkFontSize,
this.watermarkPlacement,
this.folderList,
});
String successCode;
String successMessage;
int totalPhotos;
int totalLikes;
int totalComments;
int totalShared;
int totalSelectedPhotosForAlbum;
String watermarkType;
String watermarkLogo;
String watermarkText;
String watermarkFont;
String watermarkFontColor;
int watermarkScaleHeight;
int watermarkScaleWidth;
double watermarkOpacity;
int watermarkFontSize;
String watermarkPlacement;
List<FolderList> folderList;
factory AllPhotoListing.fromJson(Map<String, dynamic> json) => AllPhotoListing(
successCode: json["SuccessCode"],
successMessage: json["SuccessMessage"],
totalPhotos: json["TotalPhotos"],
totalLikes: json["TotalLikes"],
totalComments: json["TotalComments"],
totalShared: json["TotalShared"],
totalSelectedPhotosForAlbum: json["TotalSelectedPhotosForAlbum"],
watermarkType: json["WatermarkType"],
watermarkLogo: json["WatermarkLogo"],
watermarkText: json["WatermarkText"],
watermarkFont: json["WatermarkFont"],
watermarkFontColor: json["WatermarkFontColor"],
watermarkScaleHeight: json["WatermarkScaleHeight"],
watermarkScaleWidth: json["WatermarkScaleWidth"],
watermarkOpacity: json["WatermarkOpacity"].toDouble(),
watermarkFontSize: json["WatermarkFontSize"],
watermarkPlacement: json["WatermarkPlacement"],
folderList: List<FolderList>.from(json["FolderList"].map((x) => FolderList.fromJson(x))),
);
Map<String, dynamic> toJson() => {
"SuccessCode": successCode,
"SuccessMessage": successMessage,
"TotalPhotos": totalPhotos,
"TotalLikes": totalLikes,
"TotalComments": totalComments,
"TotalShared": totalShared,
"TotalSelectedPhotosForAlbum": totalSelectedPhotosForAlbum,
"WatermarkType": watermarkType,
"WatermarkLogo": watermarkLogo,
"WatermarkText": watermarkText,
"WatermarkFont": watermarkFont,
"WatermarkFontColor": watermarkFontColor,
"WatermarkScaleHeight": watermarkScaleHeight,
"WatermarkScaleWidth": watermarkScaleWidth,
"WatermarkOpacity": watermarkOpacity,
"WatermarkFontSize": watermarkFontSize,
"WatermarkPlacement": watermarkPlacement,
"FolderList": List<dynamic>.from(folderList.map((x) => x.toJson())),
};
}
class FolderList {
FolderList({
this.folderId,
this.title,
this.totalCount,
this.photoList,
});
int folderId;
String title;
int totalCount;
List<PhotoList> photoList;
factory FolderList.fromJson(Map<String, dynamic> json) => FolderList(
folderId: json["FolderId"],
title: json["Title"],
totalCount: json["TotalCount"],
photoList: List<PhotoList>.from(json["PhotoList"].map((x) => PhotoList.fromJson(x))),
);
Map<String, dynamic> toJson() => {
"FolderId": folderId,
"Title": title,
"TotalCount": totalCount,
"PhotoList": List<dynamic>.from(photoList.map((x) => x.toJson())),
};
}
class PhotoList {
PhotoList({
this.photoId,
this.photoMainImagePath,
this.photoThumbnailImagePath, // i need this array in my api call
this.photoPreviewImagePath,
this.isSelectedPhoto,
this.isLikedPhoto,
this.photoSelectedCustomers,
this.photoSelectedPhotographerProfile,
});
int photoId;
String photoMainImagePath;
String photoThumbnailImagePath;
String photoPreviewImagePath;
int isSelectedPhoto;
int isLikedPhoto;
List<PhotoSelectedCustomer> photoSelectedCustomers;
String photoSelectedPhotographerProfile;
factory PhotoList.fromJson(Map<String, dynamic> json) => PhotoList(
photoId: json["PhotoId"],
photoMainImagePath: json["PhotoMainImagePath"],
photoThumbnailImagePath: json["PhotoThumbnailImagePath"],
photoPreviewImagePath: json["PhotoPreviewImagePath"],
isSelectedPhoto: json["IsSelectedPhoto"],
isLikedPhoto: json["IsLikedPhoto"],
photoSelectedCustomers: List<PhotoSelectedCustomer>.from(json["PhotoSelectedCustomers"].map((x) =>
PhotoSelectedCustomer.fromJson(x))),
photoSelectedPhotographerProfile: json["PhotoSelectedPhotographerProfile"],
);
Map<String, dynamic> toJson() => {
"PhotoId": photoId,
"PhotoMainImagePath": photoMainImagePath,
"PhotoThumbnailImagePath": photoThumbnailImagePath,
"PhotoPreviewImagePath": photoPreviewImagePath,
"IsSelectedPhoto": isSelectedPhoto,
"IsLikedPhoto": isLikedPhoto,
"PhotoSelectedCustomers": List<dynamic>.from(photoSelectedCustomers.map((x) => x.toJson())),
"PhotoSelectedPhotographerProfile": photoSelectedPhotographerProfile,
};
}
class PhotoSelectedCustomer {
PhotoSelectedCustomer({
this.profilePicture,
});
String profilePicture;
factory PhotoSelectedCustomer.fromJson(Map<String, dynamic> json) => PhotoSelectedCustomer(
profilePicture: json["ProfilePicture"],
);
Map<String, dynamic> toJson() => {
"ProfilePicture": profilePicture,
};
}
答案 0 :(得分:0)
你可以试试这个:
for(int i=0; i<azim.length; i++){
//print here
}