Dart Class To Create Json Encode

Dart Class To Create Json Encode :

This flutter tutorial post class to crate json. This is mostly use to list of entry input and save the server or local data.

  • Serialize json dart
  • Json encode dart
  • Data class generate json string in dart
Dart Class To Create Json Encode
import 'dart:convert';

class ASCGiveChargeEntry {
  final String bikeId;
  final List<ASCGiveCharge> listASCGiveCharge;

  ASCGiveChargeEntry(this.bikeId,  this.listASCGiveCharge);

  ASCGiveChargeEntry.fromJson(Map<String, dynamic> json)
      : bikeId = json['bikerId'],
        listASCGiveCharge = json['ascGiveCharge'];

  Map<String, dynamic> toJson() => {
    'bikerId' : bikeId,
    'ascGiveCharge':  listASCGiveCharge,

class ASCGiveCharge {
  final String jobId;
  final String itemId;
  final double qty;
  final double rate;
  final double amount;
  final double taxPercentage;
  final double taxAmt;
  final String pid;
  final String operator;
  final String condId;
  final String condType;
  final double totalAmount;

  ASCGiveCharge(this.jobId, this.itemId, this.qty, this.rate, this.amount, this.taxPercentage, this.taxAmt, this.pid, this.operator,
      this.condId, this.condType, this.totalAmount);

  ASCGiveCharge.fromJson(Map<String, dynamic> json)
      : jobId = json['jobId'],
        itemId = json['itemId'],
        qty = json['qty'],
        rate = json['rate'],
        amount = json['amount'],
        taxPercentage = json['taxPercentage'],
        taxAmt = json['taxAmt'],
        pid = json['pid'],
        operator = json['operator'],
        condId = json['condId'],
        condType = json['condType'],
        totalAmount = json['totalAmount'];

  Map<String, dynamic> toJson() => {
    'jobId' : jobId,
    'itemId' : itemId,
    'qty' : qty,
    'rate' : rate,
    'amount' : amount,
    'taxPercentage' : taxPercentage,
    'taxAmt' : taxAmt,
    'pid' : pid,
    'operator' : operator,
    'condId' : condId,
    'condType' : condType,
    'totalAmount' : totalAmount,

void main() {
  List<ASCGiveCharge> listASCGiveCharge = new List();
  listASCGiveCharge.add(ASCGiveCharge('jobId', 'itemId', 0.0, 0.1, 0.3, 0.4, 0.5, 'pid', 'operator', 'conId', 'condType', 0.6));
  listASCGiveCharge.add(ASCGiveCharge('jobId', 'itemId', 0.0, 0.1, 0.3, 0.4, 0.5, 'pid', 'operator', 'conId', 'condType', 0.6));

  ASCGiveChargeEntry entry = ASCGiveChargeEntry('0', listASCGiveCharge) ;

Output :


The flutter tutorial  is a website that bring you the latest and amazing resources of code. All the languages codes are included in this website. The languages like flutter, android, java,kotlin etc.with the help of this languages any user can develop the beautiful application

For more information about Flutter. visit www.fluttertutorial.in