I have this JSON file I want to fetch "name" field but I a have not better understanding about JSON file can anyone please explain how can I read this JOSN file format and How can I access "name" field to print. I have tried multiple code but I did not make it successful.
{
"stream": {
"tv": [{
"name": "Tv",
"description": "Tv",
"url": "this is the url",
"image": "imagelink",
}]
}
}
Here is the Code
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
void main() => runApp(HomePage());
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
List data=[];
@override
void initState() {
fetchData();
super.initState();
}
void fetchData() async {
final response =
await http.get('Link here');
if (response.statusCode == 200) {
setState(() {
data = json.decode(response.body);
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Center(
child: Text(data[0]["stream"]["adomtv"][0]["name"]),// how can I access given Json fields here
)
);
}
}