I would like to iterate through an array inside an other for loop.
I tried everything using !
%
and %%
and I can iterate i
but cannot access my array
using this i
here is the code that I would like to make it works :
rem stats.json contains -> { 1: "10%", 2: "20%", 3: "30%", 4: "40%", 5: "50%", 6: "60%" }
for /f "delims=" %%x in (stats.json) do set json=%%x
set json=%json:"=%
set "json=%json:~2,-2%"
set "json=%json:: =]=%"
set "stats[%json:, =" & set "stats[%"
echo stats[1]=%stats[1]%
echo stats[2]=%stats[2]%
echo stats[3]=%stats[3]%
echo stats[4]=%stats[4]%
echo stats[5]=%stats[5]%
echo stats[6]=%stats[6]%
set i=1
for %%f in (A, B, C) do (
set /a j=!i!*2-1
set /a k=!i!*2
echo %%f - %stats[!j!]% - %stats[!k!]%
set /a i+=1
)
anyone knows how to modifiy the for loop to make it works correctly?
j
and k
are correctly calculated but the line echo %%f - %stats[!j!]% - %stats[!k!]%
does not work at all.
Current result :
A - -
B - -
C - -
expecting result :
A - 10% - 20%
B - 30% - 40%
C - 50% - 60%