函数 parseJson 不是字符串的成员

sal*_*ma1 0 scala sendgrid

我正在使用 scala 2.12,当我尝试这个功能测试时:

  "FilterJsonProtocol" should {
    "deserialize filter to json" in {
      val filter: Filter = BCC(true, "you@example.com")
      filter.toJson shouldEqual "{\"settings\":{\"enable\":1,\"email\":\"you@example.com\"}}".parseJson
    }
  } 
i get the error Error:(14, 95) value parseJson is not a member of String
      filter.toJson shouldEqual "{\"settings\":{\"enable\":1,\"email\":\"you@example.com\"}}".parseJson
Run Code Online (Sandbox Code Playgroud)

这个函数在 scala 2.12 中不可用?还是其他问题?

Gab*_*lla 5

parseJson不是 上普遍可用的方法String

为了像这样使用它,范围内必须有一个隐式转换,可以转换String为具有parseJson方法的东西。

例如,如果您正在使用spray-json,则需要导入

import spray.json._
Run Code Online (Sandbox Code Playgroud)

然后你就可以parseJson调用String