我是第一次尝试 kotlin。
我能够在命令行上在 kotlin 中运行编译 hello world 程序,但我无法编译我想要包含外部 java 库的程序
import com.google.gson.Gson
data class Person(val name: String, val age: Int, val gender: String?)
fun main(args: Array<String>) {
println("Hello world");
val gson = Gson()
val person = Person("navin", 30, null)
val personJson = gson.toJson(person)
println(personJson)
}
Run Code Online (Sandbox Code Playgroud)
目录结构
? kotlin tree
.
??? gson.jar
??? json.jar
??? json.kt
0 directories, 3 files
? kotlin
Run Code Online (Sandbox Code Playgroud)
代码编译工作正常,但我无法运行程序
? kotlin kotlinc -classpath gson.jar json.kt -include-runtime -d json.jar
? kotlin java -jar json.jar -cp gson.jar
Hello …Run Code Online (Sandbox Code Playgroud) 我想将我的 json 转换为以下格式。并将以下格式转换为我的记录。请检查我在下面编写的代码。
{
"uid" : "bob",
"emailid" : "bob@bob.com",
"email_verified" : "Y" // "Y" for EmailVerified and "N" for EmailNotVerified
}
Run Code Online (Sandbox Code Playgroud)
我有下面的代码,我尝试使用 Haskell 中的 Aeson 库将用户类型与 json 相互转换
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric #-}
import Data.Monoid ((<>))
import GHC.Generics
import Data.Aeson (FromJSON, ToJSON)
import Data.Aeson.Types
data User = User {
userId :: String,
userEmail :: String,
userEmailVerified :: EmailState
} deriving (Show, Generic)
data EmailState = EmailVerified | EmailNotVerified deriving (Generic, Show)
instance ToJSON User where
toJSON …Run Code Online (Sandbox Code Playgroud)