Skip to content

Instantly share code, notes, and snippets.

@Quingsley
Last active August 22, 2022 13:35
Show Gist options
  • Save Quingsley/d9ae7ed0bb24f6aef947b69435e52503 to your computer and use it in GitHub Desktop.
Save Quingsley/d9ae7ed0bb24f6aef947b69435e52503 to your computer and use it in GitHub Desktop.
working-with-json-data

working-with-json-data

Created with <3 with dartpad.dev.

import 'dart:convert';
import 'package:http/http.dart' show get;
void main() async {
final clientID = 'ha_NzNADHFGe6F3m0BDREK-WDj8mqABkeRTYW8JFhFk';
final response = await get(Uri.parse('https://api.unsplash.com/photos?client_id=$clientID'));
//print(jsonDecode(response.body));
var result = ImageModel.fromJson(jsonDecode(response.body));
// print(result.url);
// print(result.tag);
print(result.imageUrl);
print(result.imageTag);
}
//model classes
class ImageModel{
var counter = 0;
var imageUrl = [];
var imageTag = [];
ImageModel.fromJson(var parsedJson){
for(counter ; counter < 10; counter++){
imageUrl.add(parsedJson[counter]['urls']['regular']);
imageTag.add(parsedJson[0]["sponsorship"]["tagline"]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment