How to parse a json string to a case class in scaja.js and vice versa

[亡魂溺海] 提交于 2019-12-10 12:48:18

问题


A JSON string:

{
    "name": "Mike",
    "age": 111
}

A case class:

case class User(name:String, age:Int)

If I use scala, there are many libraries can let me convert the JSON to the case class and vice versa, but they can't be used in scala.js.

How to do this work in scala.js?


回答1:


Use one of the pickling libraries that work with Scala.js. The following two produce well-behaved and predictable JSON:

  • uPickle
  • Prickle



回答2:


Circe has more than 1000 stars: https://github.com/circe/circe



来源:https://stackoverflow.com/questions/28586157/how-to-parse-a-json-string-to-a-case-class-in-scaja-js-and-vice-versa

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!