Crimson

Dart 的快速、高效且易于使用的 JSON 解析器和序列化器。

? Crimson 仍处于早期开发阶段,尚未准备好用于生产环境。目前仅支持解析 ?

特点

  • ?️ 快速:非常快速。Crimson 可以在一次遍历中解析 JSON。
  • 易于使用:Crimson 的设计易于使用和理解。
  • ? 灵活:Crimson 可以部分解析和序列化 JSON。
  • ? 轻量级:Crimson 轻量级且没有第三方依赖。

用法

将 Crimson 添加到您的 pubspec.yaml 后,您就可以开始使用 @json 和可选的 @JsonField 注释您的类了。

import 'package:crimson/crimson.dart';

part 'tweet.g.dart';

@json
class Tweet {
  DateTime? created_at;

  @JsonField(name: 'text')
  String? tweet;

  int? reply_count;

  int? retweet_count;

  int? favorite_count;
}

现在,您只需要运行 pub run build_runner build 来生成必要的代码。

import 'package:crimson/crimson.dart';

void main() {
  final jsonBytes = downloadTweets();
  final crimson = Crimson(jsonBytes);

  final tweets = crimson.parseTweetList();
}

就是这样!您现在可以轻松地解析和序列化 JSON 了。

许可证

Copyright 2022 Simon Choi

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   https://apache.ac.cn/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

GitHub

查看 Github