【发布时间】:2020-05-12 21:43:58
【问题描述】:
我有一个烧瓶应用程序,如果我对它执行 cURL,它会返回以下内容:
响应采用 JSON 格式,如下所示:
{"your_field": "hello there buddy"}
我只想获取值“hello there buddy”并打印出来。知道怎么做吗?
我有以下代码:
def myExampleFunction = ( text: String ) => {
val result = Http("http://localhost:5001/other/post").postData("{\"my_field\":\"" + text + "\"}")
.header("Content-Type", "application/json")
.header("Charset", "UTF-8")
.option(HttpOptions.readTimeout(10000)).asString
println("result.body is!! : " + result.body)
result.body
运行它会打印以下内容:
result.body is!! : {"your_field": "hello there buddy"}
我想要实现的是:
result.body is!! : hello there buddy
【问题讨论】:
-
我没有设置环境,但是,结果。 your_field 会工作
-
编译错误:值 your_field 不是 scalaj.http.HttpResponse[String] 的成员
标签: scala apache-spark http-post-vars