{"id":32527,"date":"2024-11-01T09:09:45","date_gmt":"2024-11-01T09:09:45","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=32527"},"modified":"2024-11-01T11:54:56","modified_gmt":"2024-11-01T11:54:56","slug":"flutter-course-15-6-json-data","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/32527\/","title":{"rendered":"Flutter Course &#8211; 15.6 JSON Data"},"content":{"rendered":"<p><body><\/p>\n<p>\n        In recent mobile app development, the JSON (JavaScript Object Notation) data format is widely used for data transmission and storage. JSON data has a structurally simple form, is highly readable compared to other data formats, and can be easily parsed in most programming languages.\n    <\/p>\n<h2>1. Definition and Characteristics of JSON<\/h2>\n<p>\n        JSON is a lightweight data interchange format that is easily readable and writable by both humans and machines. While JSON is based on the syntax of JavaScript object literals, it is also very useful for data interchange between different languages. The main characteristics of JSON are as follows:\n    <\/p>\n<ul>\n<li><strong>Lightweight<\/strong>: It has a simple structure, resulting in low overhead for data transmission.<\/li>\n<li><strong>Readability<\/strong>: It is in a format that is easy for humans to read.<\/li>\n<li><strong>Flexibility<\/strong>: It can represent complex data structures.<\/li>\n<\/ul>\n<h2>2. JSON Format<\/h2>\n<p>\n        JSON data is expressed in key-value pairs. Here is an example of a JSON object:\n    <\/p>\n<pre><code>{\n    \"name\": \"John Doe\",\n    \"age\": 30,\n    \"isDeveloper\": true,\n    \"skills\": [\"Dart\", \"Flutter\", \"JavaScript\"],\n    \"address\": {\n        \"city\": \"Seoul\",\n        \"postalCode\": \"12345\"\n    }\n}<\/code><\/pre>\n<h2>3. Using JSON Data in Flutter<\/h2>\n<p>\n        To utilize JSON data in Flutter, you can either fetch data from an external API through HTTP requests or read data from a local JSON file. This section outlines the basic procedures for using JSON data through both methods.\n    <\/p>\n<h3>3.1. Fetching JSON Data via HTTP Requests<\/h3>\n<p>\n        You can use the HTTP package in Flutter to fetch JSON data from an API.\n    <\/p>\n<p>Here is an example of code that retrieves JSON data from an API:<\/p>\n<pre><code>import 'dart:convert';\nimport 'package:http\/http.dart' as http;\n\nFuture<void> fetchData() async {\n    final response = await http.get(Uri.parse('https:\/\/api.example.com\/data'));\n\n    if (response.statusCode == 200) {\n        \/\/ Data successfully returned from the server\n        var jsonData = json.decode(response.body);\n        print(jsonData);\n    } else {\n        throw Exception('Error occurred while loading data');\n    }\n}<\/void><\/code><\/pre>\n<h3>3.2. Reading Data from a Local JSON File<\/h3>\n<p>\n        In some cases, you can read data from a built-in JSON file in the app. You can load a JSON file using the following steps.\n    <\/p>\n<p><strong>Step 1:<\/strong> Add the JSON file to the app&#8217;s <code>assets<\/code> folder.<\/p>\n<p><strong>Step 2:<\/strong> Add the assets to the <code>pubspec.yaml<\/code> file.<\/p>\n<pre><code>flutter:\n    assets:\n        - assets\/data.json<\/code><\/pre>\n<p><strong>Step 3:<\/strong> Write code to read the JSON file:<\/p>\n<pre><code>import 'dart:convert';\nimport 'package:flutter\/services.dart' as rootBundle;\n\nFuture<void> loadJsonData() async {\n    final jsonData = await rootBundle.rootBundle.loadString('assets\/data.json');\n    final data = json.decode(jsonData);\n    print(data);\n}<\/void><\/code><\/pre>\n<h2>4. Connecting JSON Data to Model Classes<\/h2>\n<p>\n        To utilize JSON data in a Flutter app, it is common to convert the data into model classes. Here is an example of how to convert JSON data into a model class.\n    <\/p>\n<pre><code>class User {\n    String name;\n    int age;\n    bool isDeveloper;\n    List<String> skills;\n\n    User({required this.name, required this.age, required this.isDeveloper, required this.skills});\n\n    factory User.fromJson(Map<String, dynamic> json) {\n        return User(\n            name: json['name'],\n            age: json['age'],\n            isDeveloper: json['isDeveloper'],\n            skills: List<String>.from(json['skills']),\n        );\n    }\n}<\/String><\/String><\/code><\/pre>\n<p>Using the class, you can easily convert JSON data into objects for use.<\/p>\n<h2>5. Displaying JSON Data in Flutter Widgets<\/h2>\n<p>\n        Once the JSON data is fetched, let&#8217;s explore how to display that data in Flutter widgets. For example, we can create a widget that displays the user information on the screen.\n    <\/p>\n<pre><code>class UserProfile extends StatelessWidget {\n    final User user;\n\n    UserProfile({required this.user});\n\n    @override\n    Widget build(BuildContext context) {\n        return Column(\n            children: [\n                Text('Name: ${user.name}'),\n                Text('Age: ${user.age}'),\n                Text('Is Developer: ${user.isDeveloper ? \"Yes\" : \"No\"}'),\n                Text('Skills: ${user.skills.join(', ')}'),\n            ],\n        );\n    }\n}<\/code><\/pre>\n<h2>6. Exception Handling and Error Management<\/h2>\n<p>\n        Handling errors that may occur during JSON data operations is very important. Let&#8217;s look at how to handle exceptions that may arise during HTTP requests or JSON parsing.\n    <\/p>\n<pre><code>Future<void> fetchData() async {\n    try {\n        final response = await http.get(Uri.parse('https:\/\/api.example.com\/data'));\n        if (response.statusCode == 200) {\n            \/\/ Successfully fetched JSON data\n            var jsonData = json.decode(response.body);\n            print(jsonData);\n        } else {\n            throw Exception('Server error: ${response.statusCode}');\n        }\n    } catch (e) {\n        print('Error occurred: $e');\n    }\n}<\/void><\/code><\/pre>\n<h2>7. Comparison of JSON and Other Data Formats<\/h2>\n<p>\n        JSON has several advantages and disadvantages when compared to other data formats such as XML and CSV. Here is a comparison between JSON and XML:\n    <\/p>\n<table>\n<tr>\n<th>Feature<\/th>\n<th>JSON<\/th>\n<th>XML<\/th>\n<\/tr>\n<tr>\n<td>Readability<\/td>\n<td>Excellent<\/td>\n<td>Average<\/td>\n<\/tr>\n<tr>\n<td>Data Size<\/td>\n<td>Small<\/td>\n<td>Large<\/td>\n<\/tr>\n<tr>\n<td>Structure<\/td>\n<td>Key-Value pairs<\/td>\n<td>Tag-based<\/td>\n<\/tr>\n<\/table>\n<h2>8. Conclusion<\/h2>\n<p>\n        In this tutorial, we covered the basic methods for handling JSON data in Flutter. By using JSON, we facilitate data management and provide the flexibility to support various required data formats. Based on the experience of using JSON data in practical projects, try to implement more functions.\n    <\/p>\n<p>If you need additional resources, please refer to the official Flutter documentation: <a href=\"https:\/\/flutter.dev\/docs\">Flutter Documentation<\/a>.<\/p>\n<footer>\n<p>\u00a9 2023 Flutter Course &#8211; All Rights Reserved.<\/p>\n<\/footer>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In recent mobile app development, the JSON (JavaScript Object Notation) data format is widely used for data transmission and storage. JSON data has a structurally simple form, is highly readable compared to other data formats, and can be easily parsed in most programming languages. 1. Definition and Characteristics of JSON JSON is a lightweight data &hellip; <a href=\"https:\/\/atmokpo.com\/w\/32527\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Flutter Course &#8211; 15.6 JSON Data&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[151],"tags":[],"class_list":["post-32527","post","type-post","status-publish","format-standard","hentry","category-flutter-course"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Flutter Course - 15.6 JSON Data - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/32527\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Flutter Course - 15.6 JSON Data - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"In recent mobile app development, the JSON (JavaScript Object Notation) data format is widely used for data transmission and storage. JSON data has a structurally simple form, is highly readable compared to other data formats, and can be easily parsed in most programming languages. 1. Definition and Characteristics of JSON JSON is a lightweight data &hellip; \ub354 \ubcf4\uae30 &quot;Flutter Course &#8211; 15.6 JSON Data&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/32527\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:09:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:54:56+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"4\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/32527\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32527\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Flutter Course &#8211; 15.6 JSON Data\",\"datePublished\":\"2024-11-01T09:09:45+00:00\",\"dateModified\":\"2024-11-01T11:54:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32527\/\"},\"wordCount\":524,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Flutter course\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/32527\/\",\"url\":\"https:\/\/atmokpo.com\/w\/32527\/\",\"name\":\"Flutter Course - 15.6 JSON Data - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:09:45+00:00\",\"dateModified\":\"2024-11-01T11:54:56+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32527\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/32527\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/32527\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Flutter Course &#8211; 15.6 JSON Data\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Flutter Course - 15.6 JSON Data - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/atmokpo.com\/w\/32527\/","og_locale":"ko_KR","og_type":"article","og_title":"Flutter Course - 15.6 JSON Data - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"In recent mobile app development, the JSON (JavaScript Object Notation) data format is widely used for data transmission and storage. JSON data has a structurally simple form, is highly readable compared to other data formats, and can be easily parsed in most programming languages. 1. Definition and Characteristics of JSON JSON is a lightweight data &hellip; \ub354 \ubcf4\uae30 \"Flutter Course &#8211; 15.6 JSON Data\"","og_url":"https:\/\/atmokpo.com\/w\/32527\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:09:45+00:00","article_modified_time":"2024-11-01T11:54:56+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"4\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/32527\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/32527\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Flutter Course &#8211; 15.6 JSON Data","datePublished":"2024-11-01T09:09:45+00:00","dateModified":"2024-11-01T11:54:56+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/32527\/"},"wordCount":524,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Flutter course"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/32527\/","url":"https:\/\/atmokpo.com\/w\/32527\/","name":"Flutter Course - 15.6 JSON Data - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:09:45+00:00","dateModified":"2024-11-01T11:54:56+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/32527\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/32527\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/32527\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Flutter Course &#8211; 15.6 JSON Data"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32527","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=32527"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32527\/revisions"}],"predecessor-version":[{"id":32528,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32527\/revisions\/32528"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=32527"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=32527"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=32527"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}