Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

The tool to convert json to dart code, support Windows,Mac,Web.

License

NotificationsYou must be signed in to change notification settings

fluttercandies/JsonToDart

Repository files navigation

The tool to convert json to dart code, support Windows,Mac,Web。

Language: English |中文简体

Download

Flutter for Windows

Flutter for Macos

Flutter for Web

Microsoft Store The function is not ,it will replace withFlutter for UWP in the future.

Use

Format

Click Format button, it will convert the Json string into Dart class structure.

Setting

Data Protection

It will protect data when convert data as T safety.

classFFConvert {FFConvert._();staticT?Function<TextendsObject?>(dynamic value) convert=<T>(dynamic value) {if (value==null) {returnnull;    }return json.decode(value.toString())asT?;  };}T?asT<TextendsObject?>(dynamic value, [T? defaultValue]) {if (valueisT) {return value;  }try {if (value!=null) {finalString valueS= value.toString();if (''isT) {return valueSasT;      }elseif (0isT) {returnint.parse(valueS)asT;      }elseif (0.0isT) {returndouble.parse(valueS)asT;      }elseif (falseisT) {if (valueS=='0'|| valueS=='1') {return (valueS=='1')asT;        }return (valueS=='true')asT;      }else {returnFFConvert.convert<T>(value);      }    }  }catch (e, stackTrace) {log('asT<$T>', error: e, stackTrace: stackTrace);return defaultValue;  }return defaultValue;}

you can override [FFConvert.convert] to handle special case.

FFConvert.convert=<TextendsObject?>(dynamic value) {if (value==null) {returnnull;    }finaldynamic output= json.decode(value.toString());if (<int>[]isT&& outputisList<dynamic>) {return output.map<int?>((dynamic e)=>asT<int>(e)).toList()asT;    }elseif (<String,String>{}isT&& outputisMap<dynamic,dynamic>) {return output.map<String,String>((dynamic key,dynamic value)=>MapEntry<String,String>(key.toString(), value.toString()))asT;    }elseif (constTestMode()isT&& outputisMap<dynamic,dynamic>) {returnTestMode.fromJson(output)asT;    }return json.decode(value.toString())asT?;  };

Array Protection

It can protect your array in case of one has some error.

voidtryCatch(Function f) {try {    f?.call();  }catch (e, stack) {debugPrint("$e");debugPrint("$stack");  }}

Traverse Array Count

The first object may be not has all properties.

We can slove it by setting traverse array count. It will traverse the array and merge the object.

1, 20, and 99 options are provided.

99 means traverse all of the array.

Property Rule

none,camel case,pascal,hungarian notation

Dart rule

camel case is recommended.

Order Property

none,ascending,descending

Add Method

Whether add [Data Protection] and [Array Protection].In fact, you only need it at first time then extract it into your code and import it.

NullSafety

Support to generate null-safety code.

File Header

You can add copyright,dart code, creator into here. support [Date yyyy MM-dd] format to generate time.

Property Readonly

none,final options are provided.

Nullable

You can set nullable if you are enable null-saftey.

Smart Nullable

When smart nullable is checked, all null fields and missing properties of the array will be automatically nullable.

Localizations

zh_hans,zh_hant and en are support.

Edit Class Info

Dart class structure are shown at right.

First column is the key in Json.

Second column is Property type or Class name. Yellow background will show if it is Class.

Third column is property name.

It will show red background if something is empty.

Generate

Click generate button, Dart code will generate at left side. Dart code will set into the clipboard.


[8]ページ先頭

©2009-2025 Movatter.jp