关于Flutter解析背景中的Json失败

时间:2018-04-18 08:38:14

标签: json parsing flutter

我尝试在https://flutter.io/cookbook/networking/background-parsing/的后台实现解析JSON,但我得到了以下错误。当我使用Android模拟器时,错误也一样。

我正在使用macO HighSierra。我安装了IntelliJ和Fluter and Dark插件。我在Flutter上测试了大多数例子,这一切都奏效了。我还创建了一个演示及其工作。我不明白为什么这不起作用。请帮忙吗?

我正在使用的代码:

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


// JSON::WEATHER 
Future<String> getWeatherData() async {
  var response = await http.get(
      Uri.encodeFull("http://api.openweathermap.org/data/2.5/forecast?q=San+Francisco&units=metric&APPID=14cc828bff4e71286219858975c3e89a"),
      headers: {
        'Accept': 'application/json'
      }
  );

  this.setState(() {
     weatherData = json.decode(response.body);
  });

  return 'Success!';
}


@override
void initState() {
  // TODO: implement initState
  super.initState();;
  this.getWeatherData();
}


// USAGE
new Text(
         weatherData['list'][0]['main']['temp_min'].toString(),
         style: new TextStyle(
            fontSize: 10.0,
            fontWeight: FontWeight.w400,
            color: Colors.white,
         ),
),
  

在调试模式下在SM G935F上启动lib / main.dart ...       初始化gradle ...       解决依赖关系......       运行'gradlew assembleDebug'......       内置构建/ app / outputs / apk / debug / app-debug.apk(31.4MB)。       I / FlutterActivityDelegate(26125):onResume将当前活动设置为此        D / libGLESv2(26125):STS_GLApi:包不允许使用DTS:com.yourcompany.parsingjsonintheackground       将文件同步到设备SM G935F ...       F / flutter(26125):[致命:flutter / fml / message_loop.cc(23)]检查失败:loop!= nullptr。   没有调用MessageLoop :: EnsureInitializedForCurrentThread   消息循环使用之前的线程。       F / libc(26125):致命信号6(SIGABRT),代码-6 in tid 26165(1.ui)        * < / strong> < em> *       构建指纹:'samsung / hero2ltexx / hero2lte:7.0 / NRD90M / G935FXXS2DRC3:user / release-keys'       修订版:'9'       ABI:'arm64'       pid:26125,tid:26165,name:1.ui&gt;&gt;&gt; com.yourcompany.parsingjsonintheackground&lt;&lt;&lt;       信号6(SIGABRT),代码-6(SI_TKILL),故障地址--------       中止消息:'[致命:flutter / fml / message_loop.cc(23)]检查失败:loop!= nullptr。   没有调用MessageLoop :: EnsureInitializedForCurrentThread   消息循环使用之前的线程。       “           x0 0000000000000000 x1 0000000000006635 x2 0000000000000006 x3 0000000000000008           x4 000000000000015f x5 0000000000000000 x6 0000007286ce8000 x7 0000000000000000           x8 0000000000000083 x9 ffffffffffffffdf x10 0000000000000000 x11 fffffffffffffffff           x12 0000000000000018 x13 0000000000000000 x14 0000000000000000 x15 000bbc6bf4faa710           x16 00000072840caee0 x17 0000007284073a28 x18 000000726095d160 x19 000000725d9ab4f8           x20 0000000000000006 x21 000000725d9ab450 x22 0000000000000000 x23 000000725d9ab020           x24 000000725d9ab038 x25 000000725d9ab040 x26 000000725d9ab060 x27 000000725d9ab098           x28 000000725d9ab009 x29 000000725d9aab00 x30 0000007284070ebc           sp 000000725d9aaae0 pc 0000007284073a30 pstate 0000000060000000       回溯:           #00 pc 000000000006ca30 /system/lib64/libc.so(tgkill + 8)           #01 pc 0000000000069eb8 /system/lib64/libc.so(pthread_kill + 64)           #02 pc 0000000000024198 /system/lib64/libc.so( raise + 24)           #03 pc 000000000001c9b0 /system/lib64/libc.so(abort + 52)           #04 pc 00000000003a6d2c /data/app/com.yourcompany.parsingjsonintheackground-1/lib/arm64/libflutter.so           #05 pc 00000000003a7474 /data/app/com.yourcompany.parsingjsonintheackground-1/lib/arm64/libflutter.so           #06 pc 000000000016dab4 /data/app/com.yourcompany.parsingjsonintheackground-1/lib/arm64/libflutter.so           #07 pc 000000000015f404 /data/app/com.yourcompany.parsingjsonintheackground-1/lib/arm64/libflutter.so           #08 pc 0000000000189b70 /data/app/com.yourcompany.parsingjsonintheackground-1/lib/arm64/libflutter.so           #09 pc 0000000000190b50 /data/app/com.yourcompany.parsingjsonintheackground-1/lib/arm64/libflutter.so           #10 pc 0000000000190674 /data/app/com.yourcompany.parsingjsonintheackground-1/lib/arm64/libflutter.so           #11 pc 00000000001921e8 /data/app/com.yourcompany.parsingjsonintheackground-1/lib/arm64/libflutter.so           #12 pc 00000000005dc220 /data/app/com.yourcompany.parsingjsonintheackground-1/lib/arm64/libflutter.so           #13 pc 0000000000830f4c /data/app/com.yourcompany.parsingjsonintheackground-1/lib/arm64/libflutter.so           #14 pc 0000000000830df8 /data/app/com.yourcompany.parsingjsonintheackground-1/lib/arm64/libflutter.so           #15 pc 000000000074d084 /data/app/com.yourcompany.parsingjsonintheackground-1/lib/arm64/libflutter.so           #16 pc 00000000000696bc /system/lib64/libc.so(________ZL15__pthread_startPv + 196)           #17 pc 000000000001dbf0 /system/lib64/libc.so(_start_thread + 16)       丢失了与设备的连接。

1 个答案:

答案 0 :(得分:0)

我在你打开的相关错误中回答: https://github.com/flutter/flutter/issues/16738