[英]Powershell handle JSON Response of rest API (drives me crazy)
我正在使用 rest API 并得到 JSON 作为响应。
{
"price": 0,
"price_currency": "EUR",
"balance": {
"API Decode": 19
},
"decode": [
{
"label": "VIN",
"value": "VSSZZZ7NZGV714632"
},
{
"label": "Make",
"value": "Seat"
},
{
"label": "Manufacturer",
"value": "Sociedad Espanola De Automoviles"
},
{
"label": "Plant Country",
"value": "Spain"
},
{
"label": "Manufacturer Address",
"value": "De Turismo S.A. (SEAT), Autovia A II KM 585, 08760 Martorell Barcelona"
},
{
"label": "Model",
"value": "Alhambra"
},
{
"label": "Check Digit",
"value": "Z"
},
{
"label": "Sequential Number",
"value": "714632"
},
{
"label": "Product Type",
"value": "Passenger car"
},
{
"label": "Model Year",
"value": 2016
},
{
"label": "Body",
"value": "Wagon"
},
{
"label": "Number of Doors",
"value": 5
},
{
"label": "Number of Axles",
"value": 2
},
{
"label": "Length (mm)",
"value": 4854
},
{
"label": "Width (mm)",
"value": 1904
},
{
"label": "Height (mm)",
"value": 1698
},
{
"label": "Track Front (mm)",
"value": 1571
},
{
"label": "Track Rear (mm)",
"value": 1617
},
{
"label": "Wheelbase (mm)",
"value": 2920
},
{
"label": "Wheel Size",
"value": "205/60 R16 96H"
},
{
"label": "Fuel Type - Primary",
"value": "Diesel"
},
{
"label": "Engine Displacement (ccm)",
"value": 1968
},
{
"label": "Transmission",
"value": "Manual/Standard"
},
{
"label": "Number of Gears",
"value": 6
},
{
"label": "ABS",
"value": 1
},
{
"label": "Emission Standard",
"value": "Euro 6"
},
{
"label": "Permitted trailer load without brakes (kg)",
"value": 750
},
{
"label": "Permitted trailer load with brakes 12% (kg)",
"value": 2200
},
{
"label": "Permitted towbar download (kg)",
"value": 100
},
{
"label": "Wheelbase Array (mm)",
"value": [
2920
]
},
{
"label": "Wheel Size Array",
"value": [
"205/60 R16 96H"
]
}
]
}
我想通过其名称访问 label VIN、Make 等的值。 我不能使用索引,因为每次返回的 JSON 都不同。 powershell 中是否有办法按名称访问“排放标准”等标签并将其用作参数?
正如评论中所暗示的,您可以使用ConvertFrom-Json
cmdlet 将JSON 解析为结构化对象:
# Read json from file
$json = Get-Content .\path\to\input.json
# Parse using ConvertFrom-Json
$data = $json |ConvertFrom-Json
# Now we can filter by name:
$VINValue = $data.decode.Where({$_.label -eq 'VIN'}).value
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.