All Things WinBatch > WinBatch
JSON count a list from values results
(1/1)
mattcarl:
Hello,
I'm using the JSON extender and can't seem to find a way to count the items in a response value.
;;;;; the JSON line:
"Amenities": ["air conditioning", "hot tub", "kitchen", "parking", "pets allowed", "satellite or cable TV", "wireless internet"]
;;;;; getting the value
theValue = jsValueGet(Json, nextFieldPath : "[Amenities]")
response>> *arr15376*
;;;;; getting the Type
TypesMap = jsConMap(theValue, @JsonType)
response>> <array>
I know I have captured the the data as values such as:
[Amenities][0] = "air conditioning"
[Amenities][1] = "hot tub"
[Amenities][2] = "kitchen"
etc....
The WIL array functions keep saying "theValue" is not an array.
Is there a way to convert JSON <array> to WIL array? or List? or String?
I'm looking for a way to count the number of items in this list?
Thanks in advance.
JTaylor:
I believe ArrInfo will provide that info.
Jim
td:
A simple example.
--- Code: Winbatch ---AddExtender("ilcjs44i.dll", 0, "ilcjs64i.dll")
;; Turn fragment into valid JSON data for this example.
jData = `{"Amenities": ["air conditioning", "hot tub", "kitchen", "parking", "pets allowed", "satellite or cable TV", "wireless internet"]}`
hData = jsParse(jData)
aData = jsValueGet(hData,"[Amenities]")
mData = jsConMap(aData)
nElem = ArrInfo(mData, 1)
Message("Number of Elements", nElem)
exit
td:
Another approach:
--- Code: Winbatch ---AddExtender("ilcjs44i.dll", 0, "ilcjs64i.dll")
;; Turn fragment into valid JSON data for this example.
jData = `{"Amenities": ["air conditioning", "hot tub", "kitchen", "parking", "pets allowed", "satellite or cable TV", "wireless internet"]}`
hData = jsParse(jData)
aData = jsValueGet(hData,"[Amenities]")
aPaths = jsKeyPaths(aData, "")
nElem = ArrInfo(aPaths, 1)
Message("Number of Elements", nElem)
mattcarl:
That did it:
The missing link was the "jsConMap" step.
mData = jsConMap(aData)
Much obliged!
Navigation
[0] Message Index
Go to full version