Skip to content

Instantly share code, notes, and snippets.

@mannuelf
Created July 18, 2022 07:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mannuelf/eb524356be2272c4fb0fb0115b780d58 to your computer and use it in GitHub Desktop.
Save mannuelf/eb524356be2272c4fb0fb0115b780d58 to your computer and use it in GitHub Desktop.
handle-json
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