| |

Flutterの練習7:http その2

httpの練習で発生していたエラーはUriの前のスペースを削除したら解決しました。(笑)


import 'dart:convert' as convert;
import 'package:http/http.dart' as http;
void main(List arguments) async {
  var url =Uri.parse('https://www.jma.go.jp/bosai/forecast/data/forecast/010000.json');
  var response = await http.get(url);
  if (response.statusCode == 200) {
    var jsonResponse = convert.jsonDecode(convert.utf8.decode(response.body.runes.toList()));
    var itemCount = jsonResponse.length;
    print('気象台の数: $itemCount.');
    for (var weatherData in jsonResponse){
      print(weatherData['name'] + ' : ' + weatherData['officeCode']);
    }
  } else {
    print('Request failed with status: ${response.statusCode}.');
  }
}

類似投稿

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

This site uses Akismet to reduce spam. Learn how your comment data is processed.