json2entity

Last updated:

0 purchases

json2entity Image
json2entity Images
Add to Cart

Description:

json2entity

json2entity #



中文
A tool for converting JSON strings into dart entity classes
support json_serializable.
无需手写,自动生成Flutter/Dart实体类文件 -- 掘金
Usage #



dependencies



dependencies:
json2entity: ^1.0.9
copied to clipboard



activate json2entity global.



pub global activate json2entity



run anywhere:



# output to stdout
j2e -j '{"result":1,"msg":"ok"}'

# output to file
j2e -j '{"result":1,"msg":"ok"}' -o output/BaseEntity
copied to clipboard
Windows users: #
If you are a Windows user, you need to escape the JSON string you entered
j2e -j '{\"result\":1,\"msg\":\"ok\"}'
SYNOPSIS:
Usage:
-j, --json Input json string
-f, --file Input json from file
-o, --output Input output file path and name
-v, --[no-]verbose Show verbose
-s, --[no-]json-serializable-support Indicates whether json-serializable is supported
-c, --[no-]camelize convert underscore to camel case
-h, --[no-]help Help
copied to clipboard
Custom
import 'package:json2entity/json2entity.dart';

main(List<String> args) {
var jsonStr = '{"result":1,"msg":"ok"}';
print(Clazz.fromJson(jsonStr).toString());
print(JsonSerializableClazz.fromJson(jsonStr).toString());
}
copied to clipboard
Output:
class AutoModel {
num result;
String msg;
AutoModel({
this.result,
this.msg
});

AutoModel.fromJson(Map < String, dynamic > json):
result=json['result'],
msg=json['msg'];
Map <String, dynamic> toJson() => {
'result':result,
'msg':msg
};
}

@JsonSerializable()
class AutoModel {
num result;
String msg;
AutoModel({
this.result,
this.msg
});

factory AutoModel.fromJson(Map<String, dynamic> json) => _$AutoModelFromJson(json);
Map<String, dynamic> toJson() => _$AutoModelToJson(this);
}
copied to clipboard
Main classes #
Clazz
Converting JSON strings into entity classes.
JsonSerializableClazz
Inheriting from Clazz, transforming JSON strings into entity classes that support json_serializable
Example #
wiki
Test #
./test_all.sh

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.