我从Json架构(属性)中提取字段,但字段不是按照架构顺序。
代码: - JSon Schema文件 -
{
"type": "object",
"required": [ "title", "description" ],
"properties": {
"title": { "type": "string" },
"description": { "type": "string" },
"termsOfServiceUrl": { "type": "string", "format": "uri" },
"contact": { "type": "integer", "format": "email" },
"license": { "type": "string" },
"licenseUrl": { "type": "string", "format": "uri" }
},
"additionalProperties": false
}
val schemafileparse = parse(schemafile)
val column_list = (schemafileparse \"properties").camelizeKeys.extract[Map[String,Any]].keySet
结果: -
Set(termsOfServiceUrl, description, contact, license, title, licenseUrl)
预期结果: -
Set(title, description, termsOfServiceUrl, contact, license, licenseUrl)
我怎样才能得到预期的结果。我将根据json配置架构单独获取数据文件。
答案 0 :(得分:0)
由于JObject默认使用HashMap
获取 JObject 值, HashMap 无序
所以也许您可以手动从JObject
收集字段名称,例如:
val column_list = (schemafileparse \ "properties") match {
case JObject(k) => k.map(i => i._1)
}