Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
代码片段在REPL
REPL
scala> import com.codahale.jerkson.Json._ scala> val t = (1, 3.14, "Fred") scala> generate(t) res5: String = {"_1":1,"_2":3.14,"_3":"Fred"}
在输出中,我想将标签分配给属性而不是_1, _2, _3。我该怎么做呢?
_1
_2
_3
使用 acase class而不是元组:
case class
case class Named(myInt: Int, thisDouble: Double, desc: String) generate(Named(1, 3.14, "Fred"))
给出:
{"myInt": 1.0,"thisDouble":3.14,"desc":"Fred"}