JSON इनपुट
जनरेट किया गया Dart
Dart classes जेनरेट करने के लिए JSON data दर्ज करें
Null safety और JSON serialization के साथ classes
JSON data से null safety और JSON serialization के साथ Dart classes जेनरेट करें
Dart classes जेनरेट करने के लिए JSON data दर्ज करें
Null safety और JSON serialization के साथ classes
फ़्लटर ऐप्स और डार्ट सेवाओं के लिए JSON प्लेटफ़ॉर्म से शून्य-सुरक्षित डार्ट फ़्लोर बनाने के लिए इस JSON से डार्ट बिल्डिंग का उपयोग करें।
चरण 1 - एक JSON नमूना पेस्ट
Import का उपयोग करें।चरण 2 - प्रारंभ क्लास विकल्प चुनें
Class Name सेट करें (उदाहरण के लिए Root)।String?)।json_serializable)।चरण 3 - जनरेट किए गए कोड की समीक्षा करें
Root Type Name, नल हैंडलिंग और फ्रेमवर्क जैसे विकल्प बदलें।चरण 4 - फ़्लटर/डार्ट में मॉडलों का उपयोग करें
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 और स्कॉच टूल संकेतक जो इस JSON से डार्ट बिल्डिंग के साथ शानदार काम करते हैं।
स्थिर डार्ट क्लासेज को JSON उदाहरणों और JSON स्कॉशिया में स्केल के लिए अध्ययन और सत्यापन।
फ़ोर्ट पेलोड को मान्य करने के लिए JSON कैटलॉग से JSON स्कॉशिया को आकर्षित करें।
रनटाइम से बचने के लिए डार्ट मॉडल बनाने से पहले JSON को तैयार करें और खरीदें।
सभी सामानों पर साझा फ़ॉर्मेट अनुबंधों के लिए टाइप करें।
Generator proper type safety के साथ Dart classes बनाता है, manual JSON serialization और json_annotation package दोनों support करता है, null values के लिए nullable types उपयोग करता है, और Dart naming conventions follow करता है।
जब json_annotation framework चुना जाता है, generated classes @JsonSerializable() annotation का उपयोग करती हैं और build_runner से fromJson/toJson methods automatically generate करती हैं। इससे type-safe JSON serialization मिलता है।
JSON में null values को Dart में nullable types (?) में map किया जाता है। Required fields constructors में 'required' keyword का उपयोग करती हैं—यह Dart के null safety principles के अनुरूप है।
Generated Dart code Dart के strong type system का लाभ उठाता है (int, double, String, bool, List, Map) और field names के लिए camelCase जैसी conventions follow करता है।