Kotlin: Difference between revisions
Jump to navigation
Jump to search
Created page with "==Data Class== data class SportsActivity ( val totalAveragePaceInMinutesPerKilometre: Double, val totalAverageSpeedInKilometresPerHour: Double, val to..." |
No edit summary |
||
Line 7: | Line 7: | ||
var dateOfActivity: Date | var dateOfActivity: Date | ||
) | ) | ||
==Writing to Gson== | |||
var mySportsActivity = SportsActivity( | |||
0.0, | |||
0.0, | |||
0, | |||
0.0, | |||
Date()) | |||
val gson = Gson() | |||
val json = gson.toJson(mySportsActivity) | |||
FileWriter("D:\\IAIN\\Output.json").use { writer -> | |||
val gson = GsonBuilder().create() | |||
gson.toJson(json, writer) | |||
} |
Revision as of 04:10, 15 January 2018
Data Class
data class SportsActivity ( val totalAveragePaceInMinutesPerKilometre: Double, val totalAverageSpeedInKilometresPerHour: Double, val totalDurationInSeconds: Int, val totalAverageDistanceInMetres: Double, var dateOfActivity: Date )
Writing to Gson
var mySportsActivity = SportsActivity( 0.0, 0.0, 0, 0.0, Date())
val gson = Gson() val json = gson.toJson(mySportsActivity)
FileWriter("D:\\IAIN\\Output.json").use { writer -> val gson = GsonBuilder().create() gson.toJson(json, writer) }