2017-05-08 30 views
0

我有下Axios公司呼叫处理JSON:如何从爱可信呼叫斯卡拉

const userInfo = {}; 
    userInfo['id'] = row['id']; 
    userInfo[cellName] = cellValue; 


axios.post(
     getServerInfo() + '/updateUser', userInfo 
    ). ..... 

其中:

function getServerInfo() { 
    return 'http://'+ window.location.hostname + ':' + window.location.port; 
} 

我需要写在斯卡拉控制器打印用户信息的信息在斯卡拉终端。如何才能做到这一点?我需要能够将userInfo的每个字段值都变为Scala对象。

回答

0

我基本上遵循:

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") 
     } 

    } 
} 

基于来自信息:https://www.playframework.com/documentation/2.5.x/ScalaBodyParsers