问题
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