GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - laxian/dart-json2entity: Dart语言的json转实体类工具 - Convert json to entity class for Dart and flutter

BranchesTags
Open more actions menu

Latest commit

 

History

70 Commits
70 Commits

Folders and files

NameName
Last commit message
Last commit date
.vscode
.vscode
 
 
bin
bin
 
 
example
example
 
 
lib
lib
 
 
test
test
 
 
.gitignore
.gitignore
 
 
CHANGELOG.md
CHANGELOG.md
 
 
LICENSE
LICENSE
 
 
README-cn.md
README-cn.md
 
 
README.md
README.md
 
 
analysis_options.yaml
analysis_options.yaml
 
 
clean.sh
clean.sh
 
 
json2entity
json2entity
 
 
pubspec.yaml
pubspec.yaml
 
 
test_all.sh
test_all.sh
 
 
test_cli.sh
test_cli.sh
 
 

Repository files navigation

json2entity

pub version

中文

A tool for converting JSON strings into dart entity classes

support json_serializable.

无需手写,自动生成Flutter/Dart实体类文件 -- 掘金

Usage

    1. dependencies
dependencies:
  json2entity: ^1.0.9
    1. activate json2entity global.

pub global activate json2entity

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

# output to file
j2e -j '{"result":1,"msg":"ok"}' -o output/BaseEntity

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

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()); 
}

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);
    }

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

About

Dart语言的json转实体类工具 - Convert json to entity class for Dart and flutter

Resources

Readme
Apache-2.0 license
Activity

Stars

37 stars

Watchers

1 watching

Forks

6 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.