मैं स्पंदन के लिए नया हूं, मैं एपीआई को सफलतापूर्वक कॉल करने में सक्षम हूं, हालांकि जब मैंने नक्शा जोड़कर अपने मॉडल वर्ग को संशोधित किया <स्ट्रिंग, गतिशील> मुझे निम्नलिखित अपवाद मिल रहा है अनचाहे अपवाद: ऑब्जेक्ट को एन्कोड करने योग्य ऑब्जेक्ट में कनवर्ट करना विफल: _LinkedHashMap
संदर्भ के लिए मेरा मॉडल वर्ग नीचे है
class Profile {
String id;
String userId;
String username;
String password;
String email;
String arabicFullNam;
String englishFullNam;
String phoneNumber;
String civilId;
int type;
bool success;
List<dynamic> errors;
Map<String,dynamic>body;
Profile({this.id, this.userId,this.username, this.password, this.arabicFullNam, this.englishFullNam, this.email,this.civilId, this.errors,this.success,this.type,this.body,this.phoneNumber});
factory Profile.fromJson(Map<String, dynamic> map) {
return Profile(
id: map["id"], userId: map["userId"],phoneNumber: map["phoneNumber"],username: map["username"], password: map["password"], englishFullNam: map["fullnameEn"], arabicFullNam: map['fullnameAr'], email: map['email'],civilId:map['civilId'], errors: map['errors'], success: map['success'],type: map['type'],body: map['body']);
}
Map<String, dynamic> toJson() {
return {"id": id, "userId": userId,"username": username, phoneNumber: "phoneNumber", "password": password, "fullnameEn": englishFullNam, "fullnameAr": arabicFullNam,"email": email, "civilId": civilId,"success": success, "type": type, "body": body};
}
@override
String toString() {
return 'Profile{id: $id,userId: $userId, username: $username, password: $password, email: $email, fullnameEn: $englishFullNam, fullnameAr: $arabicFullNam, civilId: $civilId, errors: $errors, success: $success, type: $type, body: $body, phoneNumber: $phoneNumber }';
}
}
List<Profile> profileFromJson(String jsonData) {
final data = json.decode(jsonData);
return List<Profile>.from(data.map((item) => Profile.fromJson(item)));
}
Profile postFromJson(String str) {
final jsonData = json.decode(str);
return Profile.fromJson(jsonData);
}
String profileToJson(Profile data) {
final jsonData = data.toJson();
print("##--tojson"+jsonData.toString());
return json.encode(jsonData);
}
कोई भी सहायताकाफी प्रशंसनीय होगी
2 जवाब
ये कोशिश करें
class Profile {
String id;
String userId;
String username;
String password;
String email;
String arabicFullNam;
String englishFullNam;
String phoneNumber;
String civilId;
int type;
bool success;
List<dynamic> errors;
Map<String, dynamic> body;
Profile({
this.id,
this.userId,
this.username,
this.password,
this.email,
this.arabicFullNam,
this.englishFullNam,
this.phoneNumber,
this.civilId,
this.type,
this.success,
this.errors,
this.body,
});
Map<String, dynamic> toMap() {
return {
'id': id,
'userId': userId,
'username': username,
'password': password,
'email': email,
'arabicFullNam': arabicFullNam,
'englishFullNam': englishFullNam,
'phoneNumber': phoneNumber,
'civilId': civilId,
'type': type,
'success': success,
'errors': errors,
'body': body,
};
}
factory Profile.fromMap(Map<String, dynamic> map) {
if (map == null) return null;
return Profile(
id: map['id'],
userId: map['userId'],
username: map['username'],
password: map['password'],
email: map['email'],
arabicFullNam: map['arabicFullNam'],
englishFullNam: map['englishFullNam'],
phoneNumber: map['phoneNumber'],
civilId: map['civilId'],
type: map['type'],
success: map['success'],
errors: List<dynamic>.from(map['errors']),
body: Map<String, dynamic>.from(map['body']),
);
}
String toJson() => json.encode(toMap());
factory Profile.fromJson(String source) =>
Profile.fromMap(json.decode(source));
@override
String toString() {
return 'Profile(id: $id, userId: $userId, username: $username, password: $password, email: $email, arabicFullNam: $arabicFullNam, englishFullNam: $englishFullNam, phoneNumber: $phoneNumber, civilId: $civilId, type: $type, success: $success, errors: $errors, body: $body)';
}
}
कच्चे जेसन की जांच करना सुनिश्चित करें जिसे आप पास कर रहे हैं या परिवर्तित कर रहे हैं। मुझे अशक्त के साथ समस्या हो रही थी: फोन नंबर का फोन नंबर: अशक्त।
संबंधित सवाल
नए सवाल
flutter
स्पंदन Google द्वारा बनाई गई एक ओपन-सोर्स UI सॉफ़्टवेयर डेवलपमेंट किट है। इसका उपयोग Android, iOS, Linux, Mac, Windows, Google Fuchsia और वेब के लिए एक ही कोडबेस से एप्लिकेशन विकसित करने के लिए किया जाता है। स्पंदन ऐप्स डार्ट भाषा में लिखे गए हैं।