Created with <3 with dartpad.dev.
Created
July 18, 2022 07:34
-
-
Save mannuelf/eb524356be2272c4fb0fb0115b780d58 to your computer and use it in GitHub Desktop.
handle-json
This file contains 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