从JSON创建哈希表 [英] Create Hashtable from JSON
本文介绍了从JSON创建哈希表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想获取Hashtable的JSON表示形式,例如:
I want to get a JSON representation of a Hashtable such as this:
@{Path="C:\temp"; Filter="*.js"}
ConvertTo-Json
导致:
{
"Path": "C:\\temp",
"Filter": "*.js"
}
但是,如果使用ConvertFrom-Json
将该JSON字符串转换回去,则不会得到HashTable,而是PSCustomObject.
However, if you convert that JSON string back with ConvertFrom-Json
you don't get a HashTable but a PSCustomObject.
那么如何可靠地序列化上面的Hashmap?
So how can one reliably serialize the above Hashmap?
推荐答案
$json = @{Path="C:\temp"; Filter="*.js"} | ConvertTo-Json
$hashtable = @{}
(ConvertFrom-Json $json).psobject.properties | Foreach { $hashtable[$_.Name] = $_.Value }
这篇关于从JSON创建哈希表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文