1st question
for the code, I expected the latter output is
21
HELLO
however, the real one is
21
20
HELLO
20
why 20 appears?
the code
import strUtils
import json
var a = %*[1, "hello", nil]
echo a
echo "\n"
for i in a.items():
echo i, " ", i.type
echo "\n"
for i in a.items():
if i.getInt() is int:
echo (i.getInt() + 20)
if i.getStr() is string:
echo i.getStr().toUpper
the 2nd question is, can we get the underground value of JsonNode? so that I can do
for i in a.getUnderGround():
if i is int:
echo (i + 20)
if i is string:
echo i.toUpper
I asked so question, because I met a C# code which I try to mimic in nim
I know nimlang is a static language, and I have read Is there any untyped list data type in Nim ?, like in python.<https://forum.nim-lang.org/t/4233>`_
I know nothing about C#, but a quick search says that C# is a statically-typed language. However the following code looks something unusual, at least for me.
#
static Object[,] sample_data = {
{"Yegor Kozlov", "YK", 5.0, 8.0, 10.0, 5.0, 5.0, 7.0, 6.0},
{"Gisella Bronzetti", "GB", 4.0, 3.0, 1.0, 3.5, null, null, 4.0}
};
for (int i = 0; i < sample_data.GetLength(0); i++)
{
IRow row = sheet.GetRow(2 + i);
for (int j = 0; j < sample_data.GetLength(1); j++)
{
if (sample_data[i, j] == null)
continue;
if (sample_data[i, j] is String)
{
row.GetCell(j).SetCellValue((String)sample_data[i, j]);
}
}
thanks
For your example:
import strUtils
import json
var a = %*[1, "hello", nil]
echo a
echo "\n"
for i in a.items():
echo i, " ", i.kind
echo "\n"
for i in a.items():
case i.kind
of JInt:
echo (i.getInt() + 20)
of JString:
echo i.getStr().toUpper
of JNull:
discard
else:
assert false, "unsupported"