Created with <3 with dartpad.dev.
Created
July 18, 2022 07:37
-
-
Save mannuelf/a17283ec8ffc68fac985fe408f6df4a6 to your computer and use it in GitHub Desktop.
handle-json-ImageModel
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
import 'dart:convert'; | |
void main() { | |
var rawJson = '{ "id": 1, "url": "https://google.com" }'; | |
var parsedJson = json.decode(rawJson); | |
var imageModel = ImageModel.fromJson(parsedJson); | |
print(imageModel.id); | |
print(imageModel.url); | |
} | |
class ImageModel { | |
int id = 0; | |
String url = ''; | |
ImageModel(this.id, this.url); | |
ImageModel.fromJson(parsedJson) { | |
id = parsedJson['id']; | |
url = parsedJson['url']; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment