Avatar
Avatar
Kishikawa Katsumi
@swift-5.8.1 import Foundation struct Coordinate: Codable { var latitude: Double var longitude: Double } struct Landmark: Codable { var name: String var foundingYear: Int var location: Coordinate } let landmark = Landmark( name: "Tokyo Tower", foundingYear: 1957, location: Coordinate(latitude: 35.658581, longitude: 139.745438) ) let data = try! JSONEncoder().encode(landmark) print(String(decoding: data, as: UTF8.self)) (edited)
{"foundingYear":1957,"location":{"longitude":139.745438,"latitude":35.658581},"name":"Tokyo Tower"} (edited)