如何在Scala / Play中创建JSON对象(How to create JSON object in Scala/Play)

编程入门 行业动态 更新时间:2024-10-28 15:27:56
如何在Scala / Play中创建JSON对象(How to create JSON object in Scala/Play)

我需要在Scala和Play框架中创建以下JSON对象,但是我遇到了麻烦:

{"employees":[ {"firstName":"John", "lastName":"Doe"} ]}

用于创建对象的数据来自html表单(已实现)。 到目前为止我的代码创建了以下内容

val json: JsValue = Json.toJson(formContent) //returns = {"firstName":"John", "lastName":"Doe"}

如何将“雇员”键添加到此对象?

谁能帮我?

谢谢

I need to create the following JSON object in Scala and Play framework, but I am having trouble:

{"employees":[ {"firstName":"John", "lastName":"Doe"} ]}

The data used to create the object comes from a html form (already implemented). So far my code creates the following:

val json: JsValue = Json.toJson(formContent) //returns = {"firstName":"John", "lastName":"Doe"}

How can I add the the key "employees" to this object?

Can anyone help me?

Thanks

最满意答案

Json.obj("employees"->Json.arr(JSON)) Json.obj("employees"->Json.arr(JSON))

更多推荐

本文发布于:2023-04-27 13:04:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1327099.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对象   如何在   Scala   JSON   Play

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!