在 powershell 中解释字典的 Python 字符串的最佳方法是什么?

What is the best way to interpret a Python string of a dictionary in powershell?

我的输入是以下字符串,描述了一个 Python 字典(字典),我想将它转换成一个 powershell 哈希表。我该如何进行?

{'Animals': {'Canine': ['Dog', 'Wolf'], 'Feline': 'Cat'}, 'Fruits': {'Good':['Apple','Orange'], 'Bad': ['Durian']}}

是否有一个库可以将其作为字符串输入和 return 哈希表对象?谢谢!

powershell 能够将项目从 json 转换为 psobjects。

powershell 7 添加了将其转换为哈希表的功能:

"{'Animals': {'Canine': ['Dog', 'Wolf'], 'Feline': 'Cat'}, 'Fruits': {'Good':['Apple','Orange'], 'Bad': ['Durian']}}"|ConvertFrom-Json -AsHashtable