如何将下一行(不确定这是什么格式)转换成JSON格式?
[root=Root [key1=value1, key2=value2, key3=Key3 [key3_1=value3_1, key3_2=value3_2, key3_3=Key3_3 [key3_3_1=value3_3_1]], key4=value4]]
其中Root
,Key3
,Key3_3
表示复杂元素。你知道吗
至
{
"root": {
"key1" : "value1",
"key2" : "value2",
"key3" : {
"key3_1" : "value3_1",
"key3_2" : "value3_2",
"key3_3" : {
"key3_3_1" : "value3_3_1"
}
},
"key4" : "value4
}
}
我在寻找方法,而不是解决方案。如果你对这个问题投反对票,请说明你为什么这么做。你知道吗
我不得不花了大约两个小时在这个问题上,但我想我有一些东西,可以工作的所有案件的基础上,你提供的格式。如果没有,我相信这将是一个小的变化。尽管您只要求提供这个想法,但由于我编写了代码,这里是Python代码。你知道吗
其思想是,我们将
dict
以自定义格式映射到的级别数,以及不是与这些级别对应的字符串的值数。同时,我们跟踪给定字符串中[
字符的索引。然后,我们从最里面的dict
表示开始,弹出包含[
(左)索引的堆栈并解析它们。在解析它们时,我们将它们从字符串中移除并继续。剩下的你可以在代码里读到。你知道吗我根据你提供的数据运行了它,结果如下。你知道吗
为了确保它适用于更一般的情况,我使用了这个自定义字符串。你知道吗
并分析了它。你知道吗
据我所知,这就是它应该被解析的方式。另外,请记住,不要剥离这些值,因为逻辑依赖于值末尾的空格,这些值应该以
dict
作为值(如果这有意义的话)。你知道吗设
x
为具有上述序列化的字符串。你知道吗首先,让我们用空字符串替换出现的
Root
、Key3
和Key3_3
然后,让我们将结果字符串拆分为单词和非单词
最后,用扭曲的方括号替换方括号,用
=
替换:
相关问题 更多 >
编程相关推荐