我的json文件如下:
{
"array":[
{
"name": ["na"],
"age": "15"
},
{
"name": ["aa","bb"],
"age": "12"
},
{
"name": ["rr,yy"],
"age": "22"
},
} ]
我尝试读取配置文件并获取名称和年龄
我尝试过,但是没有得到结果:
val defaultSvaipConfig = ConfigFactory.load()
val config = ConfigFactory.parseFile(new File("config.json"))
val pathFileConfig = config.getConfig("array")
我也尝试过这个:
ConfigFactory.parseFile(new File("application.json"))
config.getConfigList("mapConfig").asScala.map { conf =>
val name = config.getString("name")
val value = config.getString("age")
ConfigData(name, age)
答案 0 :(得分:0)
这可能不是您要查找的答案,但对于类似这样的事情,我想使用circe(https://github.com/circe/circe-config):
import com.typesafe.config.ConfigFactory
import io.circe.generic.auto._
import io.circe.config.syntax._
case class Something(name: List[String], age: String)
case class WholeConfig(array: List[Something])
val config: Either[Error, WholeConfig] = ConfigFactory.load.as[WholeConfig]