我如何从列表中获取对象

时间:2019-02-09 11:38:44

标签: scala playframework

我需要从User(1,Nick Holland,25,None)获取一个对象List(Map()),但我不知道如何

val a = request.body.asFormUrlEncoded.toSeq.map(a => a.map(b => b))

List(Map(name -> ArrayBuffer(), age -> ArrayBuffer(), deleteItem -> ArrayBuffer(User(1,Nick Holland,25,None)), action -> ArrayBuffer(remove)))

1 个答案:

答案 0 :(得分:1)

尝试

case class User(i: Int, str: String, i1: Int, opt: Option[String])
val l = List(Map("name" -> ArrayBuffer(), "age" -> ArrayBuffer(), "deleteItem" -> ArrayBuffer(User(1,"Nick Holland",25,None)), "action" -> ArrayBuffer("remove")))
l.head.apply("deleteItem").head //User(1,Nick Holland,25,None)