Last active
September 24, 2019 17:49
-
-
Save georgeherby/3fde03078e56efe13d31482dea8e5eef to your computer and use it in GitHub Desktop.
Get a Json from a list of Objects in Dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PaymentSlipes { | |
String name; | |
String personaId; | |
PaymentSlipes({this.name, this.personaId}); | |
Map<String, dynamic> toJson() => {'name': name, 'personaId': personaId}; | |
} | |
List encondeToJson(List<PaymentSlipes> list) { | |
List jsonList = List(); | |
list.map((item) => jsonList.add(item.toJson())).toList(); | |
return jsonList; | |
} | |
void main() { | |
PaymentSlipes objPayment = PaymentSlipes(name: "Douglas", personaId: "123425465"); | |
PaymentSlipes objPayment2 = PaymentSlipes(name: "Dave", personaId: "123425465"); | |
PaymentSlipes objPayment3 = PaymentSlipes(name: "Mike", personaId: "123425465"); | |
var list = [objPayment, objPayment2, objPayment3]; | |
var finalJson = {"payment_slips": encondeToJson(list)}; | |
print(finalJson); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment