json_class
peiffer-innovations/json_class open-source repository details.
- 星標
- 2
- 分支
- 5
- 最近推送(UTC)
- 2026年2月16日
- 專案狀態
- 已封存
原始 README
以下為英文專案原文快照,最新內容請造訪 GitHub。
Table of Contents
json_class
Singular class that when extended can encode itself to a JSON compatible map or list. This also provides convenience functions to decode from a JSON compatible map or list to the actual data model.
Using the library
Add the repo to your Flutter pubspec.yaml file.
dependencies:
json_class: <<version>>
Then run...
flutter packages get
Example
import 'package:json_class/json_class.dart';
import 'package:meta/meta.dart';
@immutable
class Person extends JsonClass {
Person({
this.age,
this.minor,
this.firstName,
this.lastName,
});
final int age;
final bool minor;
final String firstName;
final String lastName;
static Person fromDynamic(dynamic map) {
// It's recommended to use dynamic over Map<String, dynamic> because it's
// compatible with other types of map-like results such as Firebase Realtime
// Database's values or the ones returned from sqlflite.
Person result;
if (map != null) {
result = Person(
age: JsonClass.parseInt(map['age']),
minor: JsonClass.parseBool(map['minor']),
firstName: map['firstName'],
lastName: map['lastName'],
);
}
return result;
}
static List<Person> fromDynamicList(Iterable<dynamic> list) {
List<Person> results;
if (list != null) {
results = [];
for (dynamic map in list) {
results.add(fromDynamic(map));
}
}
return results;
}
@override
Map<String, dynamic> toJson() => JsonClass.removeNull({
age: age,
minor: minor,
firstName: firstName,
lastName: lastName,
});
}
語言Dart
使用的依賴
依賴清單 5 項
- intl
>=0.18.0<1.0.0 - logging
^1.2.0 - meta
^1.12.0 - flutter_lints開發依賴
^5.0.0 - test開發依賴
^1.25.8
如何選擇適合專案的儲存庫?
先依使用情境篩選,再比較專案活躍情況,最後到原始儲存庫確認使用要求。
- 透過儲存庫名稱、作者或描述搜尋,再依技術分類縮小範圍。
- 綜合星標、分支與最近推送比較專案;星標反映社群關注,不保證品質。
- 使用前在 GitHub 確認 README、授權條款與 Issues。
來源與維護
“A repository is the most basic element of GitHub.”
GitHub Docs — About repositories ↗