Dart - How to get Json object from Complex object Hierarchy

南楼画角 提交于 2019-12-25 04:25:42

问题


On Continuation to following SO Question/Answer :- How to get JSON serialized string using Dart Serialization I want to serialize complex object values in JSON, how can I achieve that using:-

Map toJson() { }

My class heirarchy is :-

class Container {
  Containerthis.DPC_ID);   
  String get Id => DPC_ID;
  String get LSDetailUrl => "http://www.indiavotes.com/pc/detail/$DPC_ID/$DB_STATEID/15";

  List<GoogleMaps.LatLng> Coordinates;
  List<LSElectionResult> ElectionData;

  var DPC_ID;
  // how to extend following method to serialize complex inner objects too?
  Map toJson() {
     return {"id": DPC_ID, "ElecData2009": ElectionData};
   }
}
class LSElectionResult {  

  String get WinnerName => DWIN_NM;
  String get WinnerParty => DWIN_PRT;
}

Here the first collection - GoogleMaps.LatLng is external class, but I want to serialize it too. But second collection member ElectionData is of my own class LSElectionResult, If I write Map toJson() implementation for LSElectionResult, will it be called automatically if I call Container.toJson() ?

I am going to compile this to JS.

来源:https://stackoverflow.com/questions/22650276/dart-how-to-get-json-object-from-complex-object-hierarchy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!