来自ScalaJS。
import upickle.default._
import scala.scalajs.concurrent.JSExecutionContext.Implicits.queue
case class Post(userId: Long, id: Long, title: String, body: String)
@JSExport
def posts() : Future[Seq[Post]] = {
val txt = """[{
"userId": 1,
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
}]"""
val p = read[Seq[Post]](txt)
println(p)
p
}
pp onFailure {
case x => println(x)
}
println(x)print: upickle.Invalid $ Data:String(data:1)
如何让它发挥作用?
答案 0 :(得分:1)
嗯..
" uPickle将Longs序列化为" 1"为了避免 Scala.js中大量数据的损坏/截断。如果他们来了 作为JSON号码,你需要输入它们作为Ints或Doubles"