Dart使用Json_object产生强类型 [英] Dart using Json_object to produce strong typing
问题描述
使用一文中概述的想法=nofollow> https://www.dartlang.org/articles/json-web-service/ ,我一直在尝试实现关于使用JsonObject和接口产生强大的JSON数据类型的部分。
Using the ideas outlined in ding the article Using Dart with JSON Web Services at https://www.dartlang.org/articles/json-web-service/, I have been trying to implement the section on using JsonObject and interfaces to produce a strong typing of JSON data.
本文指出应该写一些类似的东西。
The article indicates that one should write something like.
abstract class Language {
String language;
List targets;
Map website;
}
class LanguageImpl extends JsonObject implements Language {
LanguageImpl();
factory LanguageImpl.fromJsonString(string) {
return new JsonObject.fromJsonString(string, new LanguageImpl());
}
}
但是编译器在定义带有消息
However the compiler 'fail' at the definition of the class LanguageImpl with the message
缺少继承的成员:'Language.website','Language.targets'和
'语言。语言'
Missing inherited members: 'Language.website', 'Language.targets' and 'Language.language'
更混乱的代码会运行没有问题....
Even more confusing the code will run without a problem....
推荐答案
在Darteditor中,您将获得快速修复支持。
在LanguageImpl中设置插入符,然后按 ctrl + 1 或使用上下文菜单>快速修复。
你会得到从你自动生成的抽象基类继承的具体实现。
In Darteditor you get Quick fix support for this. Set the caret at LanguageImpl and press ctrl+1 or use the context menu > Quick fix. You get the missing concrete implementations you inherit from the abstract base class generated automatically.
Dart是一个动态语言,因此非常灵活。
该工具支持您,并尝试提供有意义的警告和提示,说明可能出错
,但不要阻止您运行程序,即使尚未完成。
Dart is a dynamic language and therefor very flexible. The tools support you and try to give meaningful warnings and hints about what could go wrong but don't prevent you running a program even when it is not yet finished.
您可以使用 @proxy注释在类上沉默警告。
这也需要类有 noSuchMethod()
实现。
You can use the @proxy annotation on the class to silent the warnings.
This also needs the class to have a noSuchMethod()
implementation.
这篇关于Dart使用Json_object产生强类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!