【发布时间】:2015-09-24 03:25:33
【问题描述】:
我需要这样形成:
{
“item” : “hardcoded_value”,
“item2” : “hardcoded_value”,
“item3” : “hardcoded_value”,
}
在我正在尝试的 exec 块中:
// list with items [“item1”, “ item2”, “ item3”]
val theList = session("itemNames").as[List[String]]
val theMap = Map.empty[String,String] // empty map
// add items from list in map
theList.foreach{ key =>
| theMap += key -> "hardcoded_value"
}
但在 += 位置出现错误。
也试过了:
theList.foreach(key => theMap += key -> "hardcoded_value" )
如何通过遍历列表将键和值插入到映射中?我是 gatling 和 scala 的新手。
【问题讨论】:
标签: scala scala-collections gatling