[英]Parse HTTP POST Response JSON Body in scala
我正在发送 http 发布请求,如下所示:
def Token(url: String, Id: String, key: String): String = {
val body =
s"""
| "id": ${Id}
| "key": ${key}
|""".stripMargin
val request = Http(url).postData(body)
.header("content-type", "application/json")
.option(HttpOptions.method("POST"))
val response = request.execute()
}
我的回复正文是这样的:
{
"token": "xyz",
"abc": "defgh"
}
我想解析这个响应以获取 Scala 中“token”(“xyz”)的值。 你怎么做到这一点?
您可以在 Play 框架上使用如下语法:
response =>
val json = response.json
println (json \ "error").asOpt[String]
你可以在这里读更多关于它的内容:
https://www.playframework.com/documentation/2.8.x/ScalaJsonHttp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.