0

Bug obtaining a value from a JSON object

I'm trying to use parseCSV to retrieve specific values from a CSV file. After using the parseCSV function with the firstLineIsHeader option set to TRUE, I can retrieve the content of the first item:

let myHeader := item(jsonArray,0);

if I then use the following variable:

let myData := text(myHeader)

Ninox returns this content:

{"EAN":"3228470052177","DESCRIPCION":"LOR INTENSE CAFE MOULU 3X250G","UNIDADES":"g","MARCA":"LOR"}

Now, if I want to retrieve the value of the first item (say, "EAN"), I need to use this notation:

myHeader.EAN

It returns

3228470052177

But if I use this other notation:

myHeader."EAN"

It the returns "EAN"

The problem is, I need to use the latter notation, as I'm iterating a list of names to retrieve specific values for a CSV, something like this:

let myColumns:= ["EAN", "DESCRIPCION"];

for col in myColumns do
    data := data + " | "+ myHeader.col;
end

data returns this:

EAN | DESCRIPCION

Instead of this:

3228470052177 | LOR INTENSE CAFE MOULU 3X250G

What I'm doing wrong?

3 replies

null
    • Ninox developper
    • Jacques_TUR
    • 2 days ago
    • Reported - view

    You need to use the item() function : https://forum.ninox.com/t/35yzbjx/item

    let myColumns:= ["EAN", "DESCRIPCION"];
    
    for col in myColumns do
        data := data + " | "+ item(myHeader,col);
    end
      • Consultant and developer
      • Javier
      • 2 days ago
      • Reported - view

       That's it! Thank you very much for the tip! 

    • Ninox developper
    • Jacques_TUR
    • 2 days ago
    • Reported - view

    And you can also extract the list of header names with a for loop: https://docs.ninext.fr/for-and-while-loops-20#_luVKJ6WJ

    myLstColumns := for key, value in myHeader do
       key;
    end;

Content aside

  • Status Answered
  • 2 days agoLast active
  • 3Replies
  • 26Views
  • 2 Following