# Parsing nested Json

{% embed url="https://www.melvinvivas.com/flutter-listview-example-using-data-from-a-rest-api/" %}
tutorial asli
{% endembed %}

![tutorial asli tanpa nest json](https://3762189661-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lzp3ilcKPKiqfMvAeZF%2F-M0RYXnHuAdxXBc5YNAJ%2F-M0R_JRLY_d1PNAeK4pJ%2Fimage.png?alt=media\&token=c46ea374-b5b7-4bba-9269-8d6c661689b0)

![format json tanpa nest](https://3762189661-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lzp3ilcKPKiqfMvAeZF%2F-M0RYXnHuAdxXBc5YNAJ%2F-M0R_eLmx6us0_EU-E_R%2Fimage.png?alt=media\&token=c30c991d-1560-4084-9c35-72ed1cad5333)

## hasil edit

```
import 'dart:async';
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;

class Job {
  final String position;
  final String company;
  final String description;

  Job({this.position, this.company, this.description});

  factory Job.fromJson(Map<String, dynamic> json) {
    return Job(
      position: json['nama'],
      company: json['kontingen'],
      description: json['kelamin'],
    );
  }
}

class JobsListView extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Column(
          children: <Widget>[
            Container(
              child: Text('ok'),
            ),
            Expanded(
              child: FutureBuilder<List<Job>>(
                future: _fetchJobs(),
                builder: (context, snapshot) {
                  if (snapshot.hasData) {
                    List<Job> data = snapshot.data;
                    return _jobsListView(data);
                  } else if (snapshot.hasError) {
                    return Text("${snapshot.error}");
                  }
                  return CircularProgressIndicator();
                },
              ),
            ),
          ],
        ),
      ),
    );
  }

  Future<List<Job>> _fetchJobs() async {
    final jobsListAPIUrl = 'http://dwirudi.com/skc/public/list_peserta';
//    final jobsListAPIUrl = 'https://mock-json-service.glitch.me/';
    final response = await http.get(jobsListAPIUrl);

    if (response.statusCode == 200) {
      List jsonResponse = json.decode(response.body)['data'];
      return jsonResponse.map((job) => new Job.fromJson(job)).toList();
    } else {
      throw Exception('Failed to load jobs from API');
    }
  }

  ListView _jobsListView(data) {
    return ListView.builder(
        itemCount: data.length,
        itemBuilder: (context, index) {
          return _tile(data[index].position, data[index].company, Icons.work);
        });
  }

  ListTile _tile(String title, String subtitle, IconData icon) => ListTile(
        title: Text(title,
            style: TextStyle(
              fontWeight: FontWeight.w500,
              fontSize: 20,
            )),
        subtitle: Text(subtitle),
        leading: Icon(
          icon,
          color: Colors.blue[500],
        ),
      );
}

```

![untuk array 'data'](https://3762189661-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lzp3ilcKPKiqfMvAeZF%2F-M0RYXnHuAdxXBc5YNAJ%2F-M0RZkhivtCV8onfBO6i%2Fimage.png?alt=media\&token=1b3ffd6b-1325-46a7-b587-dd00b2dc4d6f)

![sample Json data](https://3762189661-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lzp3ilcKPKiqfMvAeZF%2F-M0RYXnHuAdxXBc5YNAJ%2F-M0RYsncQHLnCcJF25Bf%2Fimage.png?alt=media\&token=9bd40926-42b9-4515-921c-fa1248076572)

![sample hasil](https://3762189661-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lzp3ilcKPKiqfMvAeZF%2F-M0RYXnHuAdxXBc5YNAJ%2F-M0RZ1r2qEJKTCla5ORV%2Fimage.png?alt=media\&token=cd37d04d-c767-4185-841f-08e939be50f8)

{% embed url="https://www.udemy.com/course/learn-flutter-dart-to-build-ios-android-apps/learn/lecture/15103244?start=386#bookmarks" %}
dapat solusi dari sini  :)
{% endembed %}

