var uriResponse = await http.get(
Uri.parse(
'http://~~~',
),
);
var json = jsonDecode(uriResponse.body);
return json;
final response= await http.get(Uri.https('www.google.com', '/get/'));
final url=Uri.parse('https://dapi.kakao.com/v3/search/book?target=title&query=doit;
var response=await http.get(url,
headers: {"Authorization":"KakaoAK ##비밀"});
//User 클래스
class User {
final String name;
final String email;
User(this.name, this.email);
User.fromJson(Map<String, dynamic> json)
: name = json['name'],
email = json['email'];
Map<String, dynamic> toJson() =>
{
'name': name,
'email': email,
};
}
fromJson
json string 을 object로 변환해줌
toJson
object를 json string으로 변환해줌
map 형식으로 변환, jsonEncode에서 스트링으로 만들어줌
//decoding과 데이터 사용
Map userMap = jsonDecode(jsonString);
var user = User.fromJson(userMap);
print('Howdy, ${user.name}!');
print('We sent the verification link to ${user.email}.');
//encoding
String json = jsonEncode(user);
참고자료
https://github.com/dart-lang/http/issues/536
https://muhly.tistory.com/84?category=926046
https://sysocoder.com/flutter-json-%ED%8C%8C%EC%8B%B1-%EB%B0%8F-%EA%B0%9D%EC%B2%B4-%EB%B6%84%EC%84%9D/
https://jvvp.tistory.com/1166 (map객체로 반환하는 방법)
https://medium.com/@thecodingpapa/json-flutter-61815c214eb8