搜索插件、代码仓与 APP 分类

插件详情v1.0.5

json_to_dart

一个从 JSON 字符串生成 Dart 类的库(包含解析和生成功能)。

AndroidiOSmacOSWindowsLinux
近 30 天下载
35
喜欢数
6
Pub 分数
105

安装插件

flutter pub add json_to_dart

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个 Flutter/Dart 包,可自动从 JSON 字符串生成 Dart 类,包括解析逻辑和序列化工具。它通过将 JSON 数据转换为结构良好、类型安全的 Dart 模型,简化了 JSON 数据的处理。该工具支持代码生成和运行时解析,非常适合快速开发和维护清晰一致的数据模型。它可通过 pub.dev 与 Flutter 项目无缝集成。

适合场景

  • 从 API 响应生成模型
  • 自动化 JSON 解析的样板代码
  • 简化数据层开发
  • 在 JSON 处理中启用类型安全
  • 简化应用状态管理

主要特点

  • 从 JSON 自动生成 Dart 类
  • 包含 parse 和 toJson 方法
  • 支持嵌套对象和列表
  • 提供命令行界面
  • 与 Flutter pub 包系统集成

适合对象

  • 使用 JSON API 的开发者
  • 注重代码一致性的团队
  • 需要快速创建模型的项目
  • Flutter 应用中大量使用 JSON
  • 专注于效率的前端开发人员

使用建议

  • 需要有效的 JSON 输入
  • 对于复杂结构,可能需要手动调整
  • 不适用于动态或不可预测的 JSON 格式
  • 仅限静态代码生成
  • 最好在早期开发阶段使用

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

JSON to Dart

Build Status

Given a JSON string, this library will generate all the necessary Dart classes to parse and generate JSON.

This library is designed to generate Flutter friendly model classes following the flutter's doc recommendation.

Caveats

  • When an empty array is given, it will create a List. Such weird behaviour should warn the user that there is no data to extract.
  • Equal structures are not detected yet (Equal classes are going to be created over and over).
  • Properties named with funky names (like "!breaks", "|breaks", etc) or keyword (like "this", "break", "class", etc) will produce syntax errors.
  • Array of arrays are not supported:
[[{ "isThisSupported": false }]]
[{ "thisSupported": [{ "cool": true }] }]

所属分类

依赖

依赖清单 3 项

源码仓库

使用此插件的项目

暂无相关数据。