# 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](/files/-M0R_JRLY_d1PNAeK4pJ)

![format json tanpa nest](/files/-M0R_eLmx6us0_EU-E_R)

## 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'](/files/-M0RZkhivtCV8onfBO6i)

![sample Json data](/files/-M0RYsncQHLnCcJF25Bf)

![sample hasil](/files/-M0RZ1r2qEJKTCla5ORV)

{% 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 %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://triyono.gitbook.io/fluttercheatsheet/usefull-source/untitled.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
