@JsonSerializable(nullable: false)
class User{
final String name;
final int age;
final Person person;
//final User person;
User(this.name, this.age, this.person);
factory User.fromJson(Map<String, dynamic> json) =>
_$UserFromJson(json);
@override
String toString() {
return 'User{name: $name, age: $age, person: ${person.toString()}';
}
}
Person Class like User class
json date:{
"name": "test",
"age": 5,
"person": {"name": "test1", "age": 6}
}
如果我的用户用户替换了Person
I/flutter ( 4516): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY
╞═══════════════════════════════════════════════════════════
I/flutter ( 4516): The following NoSuchMethodError was thrown building
Builder:
I/flutter ( 4516): The method '[]' was called on null.
I/flutter ( 4516): Receiver: null
I/flutter ( 4516): Tried calling: []("name")
I/flutter ( 4516):
I/flutter ( 4516): When the exception was thrown, this was the stack:
I/flutter ( 4516): #0 Object.noSuchMethod
(dart:core/runtime/libobject_patch.dart:50:5)
I/flutter ( 4516): #1 _$UserFromJson
(file:///Users/user/AndroidStudioProjects/
flutter/demo/lib/bean/User.g.dart:10:19)
I/flutter ( 4516): #2 new User.fromJson
(package:demo/bean/User.dart:16:7)
I/flutter ( 4516): #3 _$UserFromJson
(file:///Users/user/AndroidStudioProjects/flutter/
demo/lib/bean/User.g.dart:11:12)
I/flutter ( 4516): #4 new User.fromJson
(package:demo/bean/User.dart:16:7)
I/flutter ( 4516): #5 _$UserFromJson
(file:///Users/user/AndroidStudioProjects/flutter
/demo/lib/bean/User.g.dart:11:12)
I/flutter ( 4516): #6 new User.fromJson
(package:demo/bean/User.dart:16:7)
I/flutter ( 4516): #7 ParseJsonPageState.initState
(package:demo/page/ParseJsonPage.dart:23:17)
I/flutter ( 4516): #8 StatefulElement._firstBuild
(package:flutter/src/widgets/framework.dart:3791:58)
I/flutter ( 4516): #9 ComponentElement.mount
(package:flutter/src/widgets/framework.dart:3657:5)
I/flutter ( 4516): #10 Element.inflateWidget
(package:flutter/src/widgets/framework.dart:2936:14)
I/flutter ( 4516): #11 Element.updateChild
(package:flutter/src/widgets/framework.dart:2739:12)
I/flutter ( 4516): #12 SingleChildRenderObjectElement.mount
(package:flutter/src/widgets/framework.dart:4800:14)
I/flutter ( 4516): #13 Element.inflateWidget
(package:flutter/src/widgets/framework.dart:2936:14)
I/flutter ( 4516): #14 Element.updateChild
(package:flutter/src/widgets/framework.dart:2739:12)
I/flutter ( 4516): #15 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3693:16)
I/flutter ( 4516): #16 Element.rebuild
(package:flutter/src/widgets/framework.dart:3530:5)
I/flutter ( 4516): #17 ComponentElement._firstBuild
(package:flutter/src/widgets/framework.dart:3662:5)
I/flutter ( 4516): #18 ComponentElement.mount
(package:flutter/src/widgets/framework.dart:3657:5)
I/flutter ( 4516): #19 Element.inflateWidget
(package:flutter/src/widgets/framework.dart:2936:14)
I/flutter ( 4516): #20 Element.updateChild
(package:flutter/src/widgets/framework.dart:2739:12)
I/flutter ( 4516): #21 SingleChildRenderObjectElement.mount
(package:flutter/src/widgets/framework.dart:4800:14)
I/flutter ( 4516): #22 Element.inflateWidget
(package:flutter/src/widgets/framework.dart:2936:14)
I/flutter ( 4516): #23 Element.updateChild
(package:flutter/src/widgets/framework.dart:2739:12)
I/flutter ( 4516): #24 SingleChildRenderObjectElement.mount
(package:flutter/src/widgets/framework.dart:4800:14)
I/flutter ( 4516): #25 Element.inflateWidget
(package:flutter/src/widgets/framework.dart:2936:14)
I/flutter ( 4516): #26 Element.updateChild
(package:flutter/src/widgets/framework.dart:2739:12)
I/flutter ( 4516): #27 SingleChildRenderObjectElement.mount
(package:flutter/src/widgets/framework.dart:4800:14)
I/flutter ( 4516): #28 Element.inflateWidget
(package:flutter/src/widgets/framework.dart:2936:14)
I/flutter ( 4516): #29 Element.updateChild
(package:flutter/src/widgets/framework.dart:2739:12)
I/flutter ( 4516): #30 SingleChildRenderObjectElement.mount
(package:flutter/src/widgets/framework.dart:4800:14)
I/flutter ( 4516): #31 Element.inflateWidget
(package:flutter/src/widgets/framework.dart:2936:14)
I/flutter ( 4516): #32 Element.updateChild
(package:flutter/src/widgets/framework.dart:2739:12)
I/flutter ( 4516): #33 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3693:16)
I/flutter ( 4516): #34 Element.rebuild
(package:flutter/src/widgets/framework.dart:3530:5)
I/flutter ( 4516): #35 ComponentElement._firstBuild
(package:flutter/src/widgets/framework.dart:3662:5)
I/flutter ( 4516): #36 StatefulElement._firstBuild
(package:flutter/src/widgets/framework.dart:3809:11)
I/flutter ( 4516): #37 ComponentElement.mount
(package:flutter/src/widgets/framework.dart:3657:5)
I/flutter ( 4516): #38 Element.inflateWidget
(package:flutter/src/widgets/framework.dart:2936:14)
I/flutter ( 4516): #39 Element.updateChild
(package:flutter/src/widgets/framework.dart:2739:12)
I/flutter ( 4516): #40 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3693:16)
I/flutter ( 4516): #41 Element.rebuild
(package:flutter/src/widgets/framework.dart:3530:5)
I/flutter ( 4516): #42 ComponentElement._firstBuild
(package:flutter/src/widgets/framework.dart:3662:5)
I/flutter ( 4516): #43 ComponentElement.mount
(package:flutter/src/widgets/framework.dart:3657:5)
I/flutter ( 4516): #44 Element.inflateWidget
(package:flutter/src/widgets/framework.dart:2936:14)
I/flutter ( 4516): #45 Element.updateChild
(package:flutter/src/widgets/framework.dart:2739:12)
I/flutter ( 4516): #46 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3693:16)
I/flutter ( 4516): #47 Element.rebuild
(package:flutter/src/widgets/framework.dart:3530:5)
I/flutter ( 4516): #48 ComponentElement._firstBuild
(package:flutter/src/widgets/framework.dart:3662:5)
I/flutter ( 4516): #49 StatefulElement._firstBuild
(package:flutter/src/widgets/framework.dart:3809:11)
I/flutter ( 4516): #50 ComponentElement.mount
(package:flutter/src/widgets/framework.dart:3657:5)
I/flutter ( 4516): #51 Element.inflateWidget
(package:flutter/src/widgets/framework.dart:2936:14)
I/flutter ( 4516): #52 Element.updateChild
(package:flutter/src/widgets/framework.dart:2739:12)
I/flutter ( 4516): #53 SingleChildRenderObjectElement.mount
(package:flutter/src/widgets/framework.dart:4800:14)
I/flutter ( 4516): #54 Element.inflateWidget
(package:flutter/src/widgets/framework.dart:2936:14)
I/flutter ( 4516): #55 Element.updateChild
(package:flutter/src/widgets/framework.dart:2739:12)
I/flutter ( 4516): #56 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3693:16)
I/flutter ( 4516): #57 Element.rebuild
(package:flutter/src/widgets/framework.dart:3530:5)
I/flutter ( 4516): #58 ComponentElement._firstBuild
(package:flutter/src/widgets/framework.dart:3662:5)
I/flutter ( 4516): #59 ComponentElement.mount
(package:flutter/src/widgets/framework.dart:3657:5)
I/flutter ( 4516): #60 Element.inflateWidget
(package:flutter/src/widgets/framework.dart:2936:14)
I/flutter ( 4516): #61 Element.updateChild
(package:flutter/src/widgets/framework.dart:2739:12)
I/flutter ( 4516): #62 SingleChildRenderObjectElement.mount
(package:flutter/src/widgets/framework.dart:4800:14)
I/flutter ( 4516): #63 Element.inflateWidget
(package:flutter/src/widgets/framework.dart:2936:14)
I/flutter ( 4516): #64 Element.updateChild
(package:flutter/src/widgets/framework.dart:2739:12)
I/flutter ( 4516): #65 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3693:16)
I/flutter ( 4516): #66 Element.rebuild
(package:flutter/src/widgets/framework.dart:3530:5)
I/flutter ( 4516): #67 ComponentElement._firstBuild
(package:flutter/src/widgets/framework.dart:3662:5)
I/flutter ( 4516): #68 StatefulElement._firstBuild
(package:flutter/src/widgets/framework.dart:3809:11)
I/flutter ( 4516): #69 ComponentElement.mount
(package:flutter/src/widgets/framework.dart:3657:5)
I/flutter ( 4516): #70 Element.inflateWidget
(package:flutter/src/widgets/framework.dart:2936:14)
I/flutter ( 4516): #71 Element.updateChild
(package:flutter/src/widgets/framework.dart:2739:12)
I/flutter ( 4516): #72 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3693:16)
I/flutter ( 4516): #73 Element.rebuild
(package:flutter/src/widgets/framework.dart:3530:5)
I/flutter ( 4516): #74 ComponentElement._firstBuild
(package:flutter/src/widgets/framework.dart:3662:5)
I/flutter ( 4516): #75 ComponentElement.mount
(package:flutter/src/widgets/framework.dart:3657:5)
I/flutter ( 4516): #76 Element.inflateWidget
(package:flutter/src/widgets/framework.dart:2936:14)
I/flutter ( 4516): #77 Element.updateChild
(package:flutter/src/widgets/framework.dart:2739:12)
I/flutter ( 4516): #78 SingleChildRenderObjectElement.mount
(package:flutter/src/widgets/framework.dart:4800:14)
I/flutter ( 4516): #79 Element.inflateWidget
(package:flutter/src/widgets/framework.dart:2936:14)
I/flutter ( 4516): #80 Element.updateChild
(package:flutter/src/widgets/framework.dart:2739:12)
I/flutter ( 4516): #81 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3693:16)
I/flutter ( 4516): #82 Element.rebuild
(package:flutter/src/widgets/framework.dart:3530:5)
I/flutter ( 4516): #83 ComponentElement._firstBuild
(package:flutter/src/widgets/framework.dart:3662:5)
I/flutter ( 4516): #84 ComponentElement.mount
(package:flutter/src/widgets/framework.dart:3657:5)
I/flutter ( 4516): #85 Element.inflateWidget
(package:flutter/src/widgets/framework.dart:2936:14)
I/flutter ( 4516): #86 Element.updateChild
(package:flutter/src/widgets/framework.dart:2739:12)
I/flutter ( 4516): #87 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3693:16)
I/flutter ( 4516): #88 Element.rebuild
(package:flutter/src/widgets/framework.dart:3530:5)
I/flutter ( 4516): #89 ComponentElement._firstBuild
(package:flutter/src/widgets/framework.dart:3662:5)
I/flutter ( 4516): #90 StatefulElement._firstBuild
(package:flutter/src/widgets/framework.dart:3809:11)
I/flutter ( 4516): #91 ComponentElement.mount
(package:flutter/src/widgets/framework.dart:3657:5)
I/flutter ( 4516): #92 Element.inflateWidget
(package:flutter/src/widgets/framework.dart:2936:14)
I/flutter ( 4516): #93 Element.updateChild
(package:flutter/src/widgets/framework.dart:2739:12)
I/flutter ( 4516): #94 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3693:16)
I/flutter ( 4516): #95 Element.rebuild
(package:flutter/src/widgets/framework.dart:3530:5)
I/flutter ( 4516): #96 ComponentElement._firstBuild
(package:flutter/src/widgets/framework.dart:3662:5)
I/flutter ( 4516): #97 StatefulElement._firstBuild
(package:flutter/src/widgets/framework.dart:3809:11)
I/flutter ( 4516): #98 ComponentElement.mount
(package:flutter/src/widgets/framework.dart:3657:5)
I/flutter ( 4516): #99 Element.inflateWidget
(package:flutter/src/widgets/framework.dart:2936:14)
I/flutter ( 4516): #100 Element.updateChild
(package:flutter/src/widgets/framework.dart:2739:12)
I/flutter ( 4516): #101 RenderObjectElement.updateChildren
(package:flutter/src/widgets/framework.dart:4583:32)
I/flutter ( 4516): #102 MultiChildRenderObjectElement.update
(package:flutter/src/widgets/framework.dart:4915:17)
I/flutter ( 4516): #103 Element.updateChild
(package:flutter/src/widgets/framework.dart:2728:15)
I/flutter ( 4516): #104 _TheatreElement.update
(package:flutter/src/widgets/overlay.dart:507:16)
I/flutter ( 4516): #105 Element.updateChild
(package:flutter/src/widgets/framework.dart:2728:15)
I/flutter ( 4516): #106 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3693:16)
I/flutter ( 4516): #107 Element.rebuild
(package:flutter/src/widgets/framework.dart:3530:5)
I/flutter ( 4516): #108 StatefulElement.update
(package:flutter/src/widgets/framework.dart:3839:5)
I/flutter ( 4516): #109 Element.updateChild
(package:flutter/src/widgets/framework.dart:2728:15)
I/flutter ( 4516): #110 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3693:16)
I/flutter ( 4516): #111 Element.rebuild
(package:flutter/src/widgets/framework.dart:3530:5)
I/flutter ( 4516): #112 ProxyElement.update
(package:flutter/src/widgets/framework.dart:3951:5)
I/flutter ( 4516): #113 Element.updateChild
(package:flutter/src/widgets/framework.dart:2728:15)
I/flutter ( 4516): #114 SingleChildRenderObjectElement.update
(package:flutter/src/widgets/framework.dart:4807:14)
I/flutter ( 4516): #115 Element.updateChild
(package:flutter/src/widgets/framework.dart:2728:15)
I/flutter ( 4516): #116 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3693:16)
I/flutter ( 4516): #117 Element.rebuild
(package:flutter/src/widgets/framework.dart:3530:5)
I/flutter ( 4516): #118 StatefulElement.update
(package:flutter/src/widgets/framework.dart:3839:5)
I/flutter ( 4516): #119 Element.updateChild
(package:flutter/src/widgets/framework.dart:2728:15)
I/flutter ( 4516): #120 SingleChildRenderObjectElement.update
(package:flutter/src/widgets/framework.dart:4807:14)
I/flutter ( 4516): #121 Element.updateChild
(package:flutter/src/widgets/framework.dart:2728:15)
I/flutter ( 4516): #122 SingleChildRenderObjectElement.update
(package:flutter/src/widgets/framework.dart:4807:14)
I/flutter ( 4516): #123 Element.updateChild
(package:flutter/src/widgets/framework.dart:2728:15)
I/flutter ( 4516): #124 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3693:16)
I/flutter ( 4516): #125 Element.rebuild
(package:flutter/src/widgets/framework.dart:3530:5)
I/flutter ( 4516): #126 BuildOwner.buildScope
(package:flutter/src/widgets/framework.dart:2272:33)
I/flutter ( 4516): #127
_WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&
SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&
WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:673:20)
I/flutter ( 4516): #128
_WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&
SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding.
_handlePersistentFrameCallback
(package:flutter/src/rendering/binding.dart:219:5)
I/flutter ( 4516): #129
_WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&
SchedulerBinding._invokeFrameCallback
(package:flutter/src/scheduler/binding.dart:990:15)
I/flutter ( 4516): #130
_WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&
SchedulerBinding.handleDrawFrame
(package:flutter/src/scheduler/binding.dart:930:9)
I/flutter ( 4516): #131
_WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&
SchedulerBinding._handleDrawFrame
(package:flutter/src/scheduler/binding.dart:842:5)
I/flutter ( 4516): #132 _invoke (dart:ui/hooks.dart:145:13)
I/flutter ( 4516): #133 _drawFrame (dart:ui/hooks.dart:134:3)
I/flutter ( 4516):
═══════════════════════════════════════════════ ══════════════════════════════════════════════════ ═══
数据格式本身需要嵌套,并且级别序列不确定。所以我不知道如何解决这个问题。