Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I am a beginner to flutter so, help me with this thing

I am getting an error like "String is not a subtype of type int of index

`[
    {
      "id": "1",
      "name": "Deva",
      "age": "20",
      "address": {
        "streetname": "Park street",
        "area": "Jjnagar",
        "place": "Pollachi",
        "pincode": "642001"
    },
      "phonenumber": "8877665544"
    }
] `

This is my json data
I need to parse in in my code

`body: FutureBuilder(
            future:
                DefaultAssetBundle.of(context).loadString("assets/data.json"),
            builder: (context, snapshot) {
              var mydata = json.decode(snapshot.data.toString());
              return Center(
                child: Text(
                  mydata['name'],
                  style: const TextStyle(
                    color: Colors.deepPurple,
                    fontWeight: FontWeight.bold,
                    fontSize: 25,
                  ),
                ),
              );
            }));`

This is the code
how to solve it

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

actually it is a list so you can access it like this

body: FutureBuilder(
        future:
            DefaultAssetBundle.of(context).loadString("assets/data.json"),
        builder: (context, snapshot) {
          
          var mydata = json.decode(snapshot.data.toString());
          final mapData=mydata[0];
          return Center(
            child: Text(
              mapData['name'],
              style: const TextStyle(
                color: Colors.deepPurple,
                fontWeight: FontWeight.bold,
                fontSize: 25,
              ),
            ),
          );
        }));`
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading