如何在Scala中处理来自Axios调用的JSON
我有下一个axios呼叫:如何在Scala中处理来自Axios调用的JSON,json,scala,axios,Json,Scala,Axios,我有下一个axios呼叫: const userInfo = {}; userInfo['id'] = row['id']; userInfo[cellName] = cellValue; axios.post( getServerInfo() + '/updateUser', userInfo ). ..... 其中: function getServerInfo() { return 'http://'+ window.location
const userInfo = {};
userInfo['id'] = row['id'];
userInfo[cellName] = cellValue;
axios.post(
getServerInfo() + '/updateUser', userInfo
). .....
其中:
function getServerInfo() {
return 'http://'+ window.location.hostname + ':' + window.location.port;
}
我需要在Scala中编写一个控制器,以便在Scala终端上打印userInfo的信息。如何做到这一点?我需要能够将userInfo的每个字段值都输入到Scala对象中。我基本上遵循了:
class InfoFromJson() extends Controller {
def updateUser = Action { request =>
val body: AnyContent = request.body
val jsonBody: Option[JsValue] = body.asJson
println(jsonBody);
// Expecting json body
jsonBody.map { json =>
Ok("Got: " + (json \ "lastName").as[String])
}.getOrElse {
BadRequest("Expecting application/json request body")
}
}
}
根据以下信息: