Skip to content

Instantly share code, notes, and snippets.

@CoderJava
Created December 16, 2021 01:40
Show Gist options
  • Save CoderJava/e1c894cd4572cbd97d25dc79d7b8bd1f to your computer and use it in GitHub Desktop.
Save CoderJava/e1c894cd4572cbd97d25dc79d7b8bd1f to your computer and use it in GitHub Desktop.
Sample handle different JSON format
Future _loadSampleJson() async {
String jsonString = await rootBundle.loadString("assets/sample.json");
final jsonData = json.decode(jsonString);
if (jsonData['status'] == 0) {
final formatA = FormatA.fromJson(jsonData);
} else if (jsonData['status'] == 1) {
final formatB = FormatB.fromJson(jsonData);
} else {
print('Format json tidak diketahui');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment