使用数组中item的值获取索引号

时间:2018-04-11 12:54:38

标签: arrays chilkat

我需要使用items值获取数组中项目的索引号。我似乎无法在文档中看到如何实现这一目标。



$json = New-Object Chilkat.JsonObject

$jsonStr = "{ `"id`": 1, `"name`": `"A green door`", `"tags`": [`"home`", 22, `"green`"], `"price`": 125 }"

$success = $json.Load($jsonStr)
if ($success -ne $true) {
    $($json.LastErrorText)
    exit
}

#  Get the "tags" array, which contains "home", 22, "green"
$tagsArray = $json.ArrayOf("tags")
if ($tagsArray -eq $null ) {
    $("tags member not found.")
    exit
}




1 个答案:

答案 0 :(得分:0)

http://tools.chilkat.io/jsonParse.cshtml

使用JSON代码生成器

例如,如果您将以下内容放入在线工具中:

{ "id": 1, "name": "A green door", "tags": ["home", 22, "green"], "price": 125 }

你会得到

$json = New-Object Chilkat.JsonObject
#  Insert code here to load the above JSON into the json object.
$id = $json.IntOf("id")
$name = $json.StringOf("name")
$price = $json.IntOf("price")
$i = 0
$count_i = $json.SizeOfArray("tags")
while ($i -lt $count_i) {
    $json.I = $i
    $strVal = $json.StringOf("tags[i]")
    $i = $i + 1
}