intellij-idea - 在其他本地化 json 文件中查找相同的键
问题描述
我想在其他 jsons 本地化文件中找到相同的键。我的json看起来像这样。
{
"general": {
"main": {
"title": "This is a title",
"header": "This is a header",
"sub": {
"sub_thing_1": "Something",
"sub_thing_2": "Something2"
}
}
},
"other_things": {
"title": "Other title"
"sub": {
"sub_thing_1": "Something",
"sub_thing_2": "Something2"
}
}
}
如您所见,相同的键可以在更多地方
我的想法是,要生成一个包含这样的深度值的集合
例如:这个“sub_thing_2”可以在 -> ["general", "main", "sub"] 找到
有了这些信息,我可以在其他文件中找到确切的密钥。
通过这段代码,我收集了每个键的深度信息,这只是一个划痕,思考代码片段,顺便说一下,我是 Kotlin 的新手
psi?.accept(object : JsonRecursiveElementVisitor() {
override fun visitObject(o: JsonObject) {
val childrens = o.children
for (child in childrens) {
val childProp = child as JsonProperty
if (child.lastChild is JsonObject) {
depth.add(childProp.name)
visitObject(child.lastChild as JsonObject)
} else {
println(depth.toString() + childProp.name + ": " + childProp.lastChild.text)
}
}
if (depth.isNotEmpty()) {
val lastItem = depth.last();
depth.remove(lastItem)
}
}
})
我的问题是有其他更简单的方法可以做到这一点,也许没有 PSI 或者我的方向是正确的?
解决方案
推荐阅读
- c# - 无法在 EF asp.net 核心中使用一个插入查询添加多行
- xslt - 设计 XSLT 以创建逗号分隔值列表
- angular - 编辑表格内的值
- java - 使用 nodetool 为 Cassandra 快照拍摄 java.lang.NoSuchMethodException
- android - 如何以编程方式读取 TextAppearance 属性
- python - 如何在无效网址上显示错误消息?
- python - 使用 JS 后端和 Python 进行机器学习
- microsoft-graph-api - Microsoft Graph API - 创建存储桶时 PlanID 的架构验证失败,更新任务不起作用
- python - Pyomo 问题:使用规则定义约束会产生“builtin_function_or_method”对象没有属性“is_expression_type””
- clojure - 在服务器上存储老鼠的最快和最脏的方法是什么?