我正在使用Powershell 2.0(截至目前无法升级至V3.0)&我想阅读下面的Json对象。
"{\"DevResults\":[{\"TechnologyName\":\"AD\",\"RuleName\":\"SOA account (user logon/display name)\",\"OutputValue\":\"SOADevClientCenter\"},
{\"TechnologyName\":\"AD\",\"RuleName\":\"SOA account (pre-Windows 2000)\",\"OutputValue\":\"SOADevCliCen\"},
\"ProdResults\":[{\"TechnologyName\":\"AD\",\"RuleName\":\"SOA account (user logon/display name)\",\"OutputValue\":\"SOAClientCenter\"},
{\"TechnologyName\":\"AD\",\"RuleName\":\"BPM Service Account (pre-Windows 2000)\",\"OutputValue\":\"BPM_CliCen_05\"}]}"
请你帮我一下。
感谢。
答案 0 :(得分:31)
您可能拥有System.Web.Extensions,因此您可以加载该程序集并使用可用的JSON parser。这是一个快速示例:
[System.Reflection.Assembly]::LoadWithPartialName("System.Web.Extensions")
$json = "{a:1,b:2,c:{nested:true}}"
$ser = New-Object System.Web.Script.Serialization.JavaScriptSerializer
$obj = $ser.DeserializeObject($json)
参考:http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx