javascript
js修改本地json文件_Flutter加载本地JSON文件教程建议收藏
今天農(nóng)村老家的天氣不是很好
而且外面還下雨了,每天只能坐在老家
打開(kāi)電腦,看看文章,寫寫文章
今天我給大家?guī)?lái)一篇Flutter加載本地JSON文件教程
本頭條核心宗旨
歡迎來(lái)到「技術(shù)剛剛好」作者,「技術(shù)剛剛好」是個(gè)人維護(hù),每天至少更新一篇Flutter技術(shù)文章,實(shí)時(shí)為大家播報(bào)Flutter最新消息。如果你剛好也在關(guān)注Flutter這門技術(shù),那就跟我一起學(xué)習(xí)進(jìn)步吧,你的贊,收藏,轉(zhuǎn)發(fā)是對(duì)我個(gè)人最大的支持,維護(hù)不易,歡迎關(guān)注。
技術(shù)剛剛好經(jīng)歷
近幾年,移動(dòng)端跨平臺(tái)開(kāi)發(fā)技術(shù)層出不窮,從Facebook家的ReactNative,到阿里家WEEX,前端技術(shù)在移動(dòng)端跨平臺(tái)開(kāi)發(fā)中大展身手,技術(shù)剛剛好作為一名Android開(kāi)發(fā),經(jīng)歷了從Reactjs到Vuejs的不斷學(xué)習(xí)。而在2018年,我們的主角變成了Flutter,這是Goolge開(kāi)源的一個(gè)移動(dòng)端跨平臺(tái)解決方案,可以快速開(kāi)發(fā)精美的移動(dòng)App。希望跟大家一起學(xué)習(xí),一起進(jìn)步!
本文核心要點(diǎn)
JSON文件數(shù)據(jù)
[ { "name": "Luke Skywalker", "height": "172", "mass": "77", "hair_color": "blond", "skin_color": "fair", "eye_color": "blue", "birth_year": "19BBY", "gender": "male" }, { "name": "C-3PO", "height": "167", "mass": "75", "hair_color": "n/a", "skin_color": "gold", "eye_color": "yellow", "birth_year": "112BBY", "gender": "n/a" }, { "name": "R2-D2", "height": "96", "mass": "32", "hair_color": "n/a", "skin_color": "white, blue", "eye_color": "red", "birth_year": "33BBY", "gender": "n/a" }, { "name": "Darth Vader", "height": "202", "mass": "136", "hair_color": "none", "skin_color": "white", "eye_color": "yellow", "birth_year": "41.9BBY", "gender": "male" }, { "name": "Leia Organa", "height": "150", "mass": "49", "hair_color": "brown", "skin_color": "light", "eye_color": "brown", "birth_year": "19BBY", "gender": "female" }, { "name": "Owen Lars", "height": "178", "mass": "120", "hair_color": "brown, grey", "skin_color": "light", "eye_color": "blue", "birth_year": "52BBY", "gender": "male" }, { "name": "Beru Whitesun lars", "height": "165", "mass": "75", "hair_color": "brown", "skin_color": "light", "eye_color": "blue", "birth_year": "47BBY", "gender": "female" }, { "name": "R5-D4", "height": "97", "mass": "32", "hair_color": "n/a", "skin_color": "white, red", "eye_color": "red", "birth_year": "unknown", "gender": "n/a" }, { "name": "Biggs Darklighter", "height": "183", "mass": "84", "hair_color": "black", "skin_color": "light", "eye_color": "brown", "birth_year": "24BBY", "gender": "male" }, { "name": "Obi-Wan Kenobi", "height": "182", "mass": "77", "hair_color": "auburn, white", "skin_color": "fair", "eye_color": "blue-gray", "birth_year": "57BBY", "gender": "male" }]項(xiàng)目結(jié)構(gòu)如下
項(xiàng)目結(jié)構(gòu)
核心代碼
import 'dart:convert';import 'package:flutter/material.dart';void main() { runApp(MaterialApp( home: MyApp(), ));}class MyApp extends StatefulWidget { @override MyAppState createState() => MyAppState();}class MyAppState extends State { List data; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text("Load local JSON file"), ), body: Container( child: Center( // Use future builder and DefaultAssetBundle to load the local JSON file child: FutureBuilder( future: DefaultAssetBundle .of(context) .loadString('data_repo/starwars_data.json'), builder: (context, snapshot) { // Decode the JSON var new_data = json.decode(snapshot.data.toString()); return ListView.builder( // Build the ListView itemBuilder: (BuildContext context, int index) { return Card( child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Text("Name: " + new_data[index]['name']), Text("Height: " + new_data[index]['height']), Text("Mass: " + new_data[index]['mass']), Text( "Hair Color: " + new_data[index]['hair_color']), Text( "Skin Color: " + new_data[index]['skin_color']), Text( "Eye Color: " + new_data[index]['eye_color']), Text( "Birth Year: " + new_data[index]['birth_year']), Text("Gender: " + new_data[index]['gender']) ], ), ); }, itemCount: new_data == null ? 0 : new_data.length, ); }), ), )); }}謝謝觀看技術(shù)剛剛好的文章,技術(shù)剛剛好是個(gè)人維護(hù),每天至少更新一篇Flutter技術(shù)文章,實(shí)時(shí)為大家播報(bào)Flutter最新消息。如果你剛好也在關(guān)注Flutter這門技術(shù),那就跟我一起學(xué)習(xí)進(jìn)步吧,你的贊,收藏,轉(zhuǎn)發(fā)是對(duì)我個(gè)人最大的支持,維護(hù)不易,歡迎關(guān)注。
總結(jié)
以上是生活随笔為你收集整理的js修改本地json文件_Flutter加载本地JSON文件教程建议收藏的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Win12正全力开发!微软重构操作系统底
- 下一篇: spring boot 跨域请求_Spr