Created
December 16, 2021 01:40
-
-
Save CoderJava/e1c894cd4572cbd97d25dc79d7b8bd1f to your computer and use it in GitHub Desktop.
Sample handle different JSON format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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