I have a config in json format and I am using Typesafe Config library to load this.
我有一个json格式的配置,我使用Typesafe配置库来加载它。
Input config in json format
以json格式输入配置
{
"input": {
"Date": "2014-01-01",
"Ids": ["1","2","3","4"]
}
}
Code
import com.typesafe.config.{Config, ConfigFactory}
val config = ConfigFactory.load("test.json")
val ids = config.getList("input.Ids").unwrapped
# ids: java.util.List[Object] = [1, 2, 3, 4]
All I am getting is list of object. When I try to do a map of each element to int it fails because each element is an object.
我得到的只是对象列表。当我尝试将每个元素的映射都设置为int时,它会失败,因为每个元素都是一个对象。
ids.map(_.toInt)
<console>:14: error: value toInt is not a member of Object
ids.map(_.toInt)
How to convert the object list to integer list in scala ?
如何将对象列表转换为scala中的整数列表?
1 个解决方案
#1
You can use the getStringList
method and then map the result to int
您可以使用getStringList方法,然后将结果映射到int
config.getStringList("input.Ids").map(_.toInt)
or in this case use the getIntList
method directly
或者在这种情况下直接使用getIntList方法
#1
You can use the getStringList
method and then map the result to int
您可以使用getStringList方法,然后将结果映射到int
config.getStringList("input.Ids").map(_.toInt)
or in this case use the getIntList
method directly
或者在这种情况下直接使用getIntList方法