0

来自 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) 打印:upickle.Invalid$Data: String (data: 1)

如何让它发挥作用?

更新/同步:https ://github.com/lihaoyi/upickle-pprint/issues/154

4

1 回答 1

1

嗯..

“uPickle 将 Longs 序列化为“1”,以避免 Scala.js 中大量数字的损坏/截断。如果它们以 JSON 数字形式出现,则需要将它们键入为 Ints 或 Doubles”

于 2016-04-28T02:22:30.207 回答