【问题标题】:remove slash from JSON从 JSON 中删除斜线
【发布时间】:2017-07-21 11:37:55
【问题描述】:

这里我使用write() JSON 序列化方法将案例类转换为 JSON 对象。 例如 - case class Data("data":String) 我想把它转换成 json 然后它可以通过

val json = net.liftweb.json.serialization.write(Data("here is something"))

然后将其转换为{"data":"here is something"}

但如果我也想将它转换成另一个 json 对象,例如 -

case class Result("message":String , Information : String)

val result =  net.liftweb.json.serialization.write(Result("success",json))

然后结果显示为 -

{"message":"success" , "Information":{"{"\data\":"\here is something\"}"}}

但我不想在 result 中使用斜线。那么删除它的最佳方案是什么。

我可以在这里做的一种方法是使用 result.replace("\","") 。 但是我在这里使用了很多路线,所以这不是我在任何地方更改它的最佳方案,因此要在任何地方删除斜线应该是最好的方法

【问题讨论】:

  • 嗯……这就是 Scala/Java 中的字符串。 String 中的任何双引号都必须是 escaped`. It is actually just {"data":"here is something"}` 和 `` 只是为了让您能够理解。
  • 我想实际上你想要的是这个:val result = net.liftweb.json.serialization.write(Result("success", Data("data"))

标签: json scala serialization


【解决方案1】:

试试case class Result("message":String , Information : Data)

【讨论】:

    猜你喜欢
    • 2012-07-02
    • 2021-02-24
    • 2018-11-06
    • 1970-01-01
    • 1970-01-01
    • 2011-01-16
    • 2018-04-14
    • 2014-07-23
    • 2018-02-17
    相关资源
    最近更新 更多