如何将json字符串解析为scaja.js中的case类,反之亦然 [英] How to parse a json string to a case class in scaja.js and vice versa

查看:108
本文介绍了如何将json字符串解析为scaja.js中的case类,反之亦然的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JSON字符串:

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

案例类:

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

如果我使用scala,有很多库可以让我将JSON转换为case类,反之亦然,但是不能在scala.js中使用它们.

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.

如何在scala.js中完成这项工作?

How to do this work in scala.js?

推荐答案

使用与Scala.js一起使用的酸洗库之一.以下两个产生行为良好且可预测的JSON:

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

  • uPickle
  • Prickle

这篇关于如何将json字符串解析为scaja.js中的case类,反之亦然的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆