JSON 입력
생성된 Dart
Dart 클래스를 생성하려면 JSON 데이터를 입력하세요
null safety 및 JSON 직렬화를 지원하는 클래스
JSON 데이터에서 null safety 및 JSON 직렬화를 지원하는 Dart 클래스 생성
Dart 클래스를 생성하려면 JSON 데이터를 입력하세요
null safety 및 JSON 직렬화를 지원하는 클래스
이 JSON-Dart 생성기를 사용하여 Flutter 앱 및 Dart 서비스용 JSON 샘플에서 null 안전 Dart 클래스를 생성하세요.
1단계 - JSON 샘플 붙여넣기
Import을 사용하여 파일, URL 또는 샘플 데이터에서 JSON을 로드합니다.2단계 – Dart 클래스 옵션 선택
Class Name을 설정합니다(예: Root).String?).json_serializable)을 선택하세요.3단계 – 생성된 코드 검토
Root Type Name, null 처리 및 프레임워크와 같은 옵션을 조정합니다.4단계 - Flutter/Dart에서 모델 사용
lib/models 아래)에 추가합니다.fromJson 팩토리 또는 생성된 직렬 변환기를 사용하여 JSON을 모델로 구문 분석합니다.flutter format을 실행하세요.5단계 - 복사 또는 다운로드
빠른 팁
DateTime 구문 분석을 사용하세요.// JSON 입력
{
"id": 123,
"name": "Maeve Winters",
"email": "[email protected]",
"active": true,
"roles": ["admin", "editor"],
"metadata": { "plan": "pro" },
"createdAt": "2024-03-01T10:15:00Z",
"score": 99.5,
"notes": null
}
// Generated Dart models (simplified)
class Metadata {
final String plan;
const Metadata({required this.plan});
}
class Root {
final int id;
final String name;
final String? email;
final bool active;
final List<String> roles;
final Metadata metadata;
final String createdAt;
final double score;
final Object? notes;
const Root({
required this.id,
required this.name,
required this.email,
required this.active,
required this.roles,
required this.metadata,
required this.createdAt,
required this.score,
required this.notes,
});
}이 JSON-Dart 생성기와 함께 훌륭하게 작동하는 더 많은 JSON 및 스키마 도구를 살펴보세요.
생성기는 올바른 타입 안전성을 가진 Dart 클래스를 생성하고, 수동 JSON 직렬화와 json_annotation 패키지 모두를 지원하며, null 값에는 nullable 타입(?)을 사용하고, Dart 네이밍 규칙을 따릅니다.
json_annotation 프레임워크를 선택하면, 생성된 클래스가 @JsonSerializable() 주석을 사용하고 build_runner로 fromJson/toJson 메서드를 자동 생성합니다. 이를 통해 타입 안전한 JSON 직렬화를 제공합니다.
JSON의 null 값은 Dart의 nullable 타입(?)에 매핑되어 null safety를 제공합니다. 필수 필드는 생성자에서 'required' 키워드를 사용하여 Dart의 null safety 원칙을 따릅니다.
생성된 Dart 코드는 int, double, String, bool, List, Map 등 적절한 타입을 사용하고, 필드 이름은 camelCase 등 Dart 관례를 따릅니다.