Home > database >  showing key along side data json
showing key along side data json

Time:12-13

Hi I have a dynamic json the details in it changes in every product so I wanna show keys along side their corresponding data any example would be great I am struggling with this. sample json in appDetails wanna show all the keys like systemoverview,benefits, mainFeatures and their data.

IN next product it will be changed but appdetails will remain same.

{
    
    "appDetails": [
      {
        "systemOverview": "https:url.com",
        "multiDeviceSupport": [
          {"label": "Multi-Device"}
          
        ],
        "mainFeatures": [
          {"label": "Testing"}
         
        ],
        "benefits": [
          {"label": "Easy & quick solution "},
          {"label": "Go paperless "}
        
        ]
      }
    ]
  };

CodePudding user response:

so taking your example:

final map = {
    
    "appDetails": [
      {
        "systemOverview": "https:url.com",
        "multiDeviceSupport": [
          {"label": "Multi-Device"}
          
        ],
        "mainFeatures": [
          {"label": "Testing"}
         
        ],
        "benefits": [
          {"label": "Easy & quick solution "},
          {"label": "Go paperless "}
        
        ]
      }
    ]
  };

we can get both the key and value using the entries like this:

map!["appDetails"]![0].entries.forEach((e) {
    
    print("${e.key}, ${e.value}");
  });

This code will print this result:

systemOverview, https:url.com
multiDeviceSupport, [{label: Multi-Device}]
mainFeatures, [{label: Testing}]
benefits, [{label: Easy & quick solution }, {label: Go paperless }]

it will print the key along with it's value, you can use this sample to achieve your result.

CodePudding user response:

print all keys of JSON data

var data = convert.jsonDecode(response.body);
print(data.keys.toList());
  • Related