修改将在perl中使用JSON编码的数据结构 [英] Modifying data structure that will be encoded using JSON in perl
本文介绍了修改将在perl中使用JSON编码的数据结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个JSON,正在尝试使用Perl代码进行修改.
I have a JSON whcih i am trying to modify using perl code.
{
"Person":{
"personalData": {
"workList": {
"file":{
"fileName": "/usr/temp/ABC.txt" }
},
}
}
}
}
我需要将上面的JSON转换为这样的内容:
I need to convert the above JSON into something like this:
{
"Person":{
"personalData": {
"workList": {
"directoryList":{
"directory":[
"file":{
"fileName": "/usr/temp/ABC.txt" }
}
]
}
}
}
}
}
有人可以举出一些在perl中执行此操作的示例吗?
Can someone give some example of doing this in perl.
推荐答案
$data->{Person}{personalData}{workList}{directoryList}{directory} =
[ delete $data->{Person}{personalData}{workList}{file} ];
或更简洁地说,
$tmp = $data->{Person}{personalData}{workList};
$tmp->{directoryList}{directory} = [ delete $tmp->{file} ];
有关其工作原理的解释,请参见:如何替换Perl哈希键?
For an explanation of how this works see: How to replace a Perl hash key?
这篇关于修改将在perl中使用JSON编码的数据结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文