1

i got all the parameters jsonEncode then i will pass http post. i have explained below the via source code.

 var abc =  jsonEncode({
        "requisitionID": "x",
        "RetailerTitle": "Faruqe Ahmed  Store",
        "RetailerAddress" : "Dhaka Nilkhet",
        "Market": "Nilkhet",
        "RetailerAreaType":"R",
        "RetailerType":"R",
        "RetailerProprieterName": "Faruqe Ahmed",
        "RetailerContactNumber": "01736611372",
        "Longitude": "Longitude",
        "Lattitude": "Lattitude",
        "Thana": {"ThanaID": "Shahbag"},
        "District": {"DistrictID": "Dhaka"},
        "EntryParameter": {"CompanyID": "x"},
        "EntryParameter": {"LocationID": "x"},
        "EntryParameter": {"MachineID": "x"},
        "EntryParameter": {"EntryBy": "D180064"},
        "EntryParameter": {"UpdateBy": "x"},
        "ImageFieldBanner": ""
      }),

but when i get string from print(abc .toString()). then i got only

{
        "requisitionID": "x",
        "RetailerTitle": "Faruqe Ahmed  Store",
        "RetailerAddress" : "Dhaka Nilkhet",
        "Market": "Nilkhet",
        "RetailerAreaType":"R",
        "RetailerType":"R",
        "RetailerProprieterName": "Faruqe Ahmed",
        "RetailerContactNumber": "01736611372",
        "Longitude": "Longitude",
        "Lattitude": "Lattitude",
        "Thana": {"ThanaID": "Shahbag"},
        "District": {"DistrictID": "Dhaka"},
        "EntryParameter": {"UpdateBy": "x"},
        "ImageFieldBanner": ""
      }

skip

   "EntryParameter": {"CompanyID": "x"},
        "EntryParameter": {"LocationID": "x"},
        "EntryParameter": {"MachineID": "x"},
        "EntryParameter": {"EntryBy": "D180064"},

i need

{
        "requisitionID": "x",
        "RetailerTitle": "Faruqe Ahmed  Store",
        "RetailerAddress" : "Dhaka Nilkhet",
        "Market": "Nilkhet",
        "RetailerAreaType":"R",
        "RetailerType":"R",
        "RetailerProprieterName": "Faruqe Ahmed",
        "RetailerContactNumber": "01736611372",
        "Longitude": "Longitude",
        "Lattitude": "Lattitude",
        "Thana": {"ThanaID": "Shahbag"},
        "District": {"DistrictID": "Dhaka"},
        "EntryParameter": {"CompanyID": "x"},
        "EntryParameter": {"LocationID": "x"},
        "EntryParameter": {"MachineID": "x"},
        "EntryParameter": {"EntryBy": "D180064"},
        "EntryParameter": {"UpdateBy": "x"},
        "ImageFieldBanner": ""
      }

1 Answers1

1

The argument you give to the jsonEncode method is a Map<String, String>, a map uses unique keys to access its values.

Your map uses the key "EntryParameter" multiple times, which results in the same value being overwritten multiple times, where only the last value remains.

To solve it you'd probably need to put your key-value pairs in an Array and create the required json code yourself, if the output structure is important.

Example

Untested code, but it should make it clear how to do this, the variable jsonManualData should contain the exact json string you need:

Map<String, dynamic> data = {
  "requisitionID": "x",
  "RetailerTitle": "Faruqe Ahmed  Store",
  "RetailerAddress": "Dhaka Nilkhet",
  "Market": "Nilkhet",
  "RetailerAreaType": "R",
  "RetailerType": "R",
  "RetailerProprieterName": "Faruqe Ahmed",
  "RetailerContactNumber": "01736611372",
  "Longitude": "Longitude",
  "Lattitude": "Lattitude",
  "Thana": {"ThanaID": "Shahbag"},
  "District": {"DistrictID": "Dhaka"},
  "EntryParameter": [
    {"CompanyID": "x"},
    {"LocationID": "x"},
    {"MachineID": "x"},
    {"EntryBy": "D180064"},
    {"UpdateBy": "x"},
  ],
  "ImageFieldBanner": ""
};

String jsonData = jsonEncode(data);
String jsonManualData = "{${data.entries.map((e) => '"${e.key}": ${jsonEncode(e.value)}').join(",")}}";
semvdwal
  • 215
  • 2
  • 12