Someone available to guide me

If I receive data in string format (I have already split the separators) and I receive a list like the one shown below, how do I do a select list item, because when I want to do it, it tells me that it is not a valid argument.

String example:

[“1749681227813”, “Botella”, “150”, “100”, “https://i.ibb.co/nqXYmMVF/f432e564f944.jpg”, “166”]

If anyone has time and would like to guide me through the steps to assemble the blocks to create the select list item, I’d appreciate it. Thank you.

u should spitl at ,
and also how me your response data mean get value

??? whats?

one by one debug block to find error by “DO IT”

There are 2 debugging tags, for two different tables, I also need to select both lists to combine data.

Do you want to make it as single list?

I have a test DB, in which I have 2 tables, in the first I have ID, product, price, stock, and image. and in the second I have the ID, name and phone number. I want the IDs to be compared and as a result: the same ID (they share it in both tables) and the image, and they are combined with NAME and PHONE from table 2. I don’t know if I explained myself well. to capture this data in a cardview

Have you tried this extension?

i believe you are having list of lists in your Db.

Extract the whole list, then by using the block FilterListOfListsByIndex filter the lists then do what else you want

I’ll check it now.

do you want to formate this

[
  {
    "id": "1749681227813",
    "user_name": "manuel alejandro",
    "user_phone": "1157222512",
    "user_age": "67",
    "product_name": "Botella",
    "price": "150",
    "stock": "100",
    "image": "https://i.ibb.co/nqXYmMVF/f432e564f944.jpg",
    "code": "166"
  },
  {
    "id": "1749774030030",
    "user_name": "alejandro molina",
    "user_phone": "1127636541",
    "user_age": "100",
    "product_name": "miel",
    "price": "1500",
    "stock": "20",
    "image": "https://ibb.co/1YbDHtx6/726d306ae6fd.jpg",
    "code": "199"
  },
  {
    "id": "1749946948757",
    "product_name": "remera",
    "price": "500",
    "stock": "4",
    "image": "https://i.ibb.co/DT654xq/7739944c3b25.jpg",
    "code": "232"
  }
]

The IDs from both tables must be combined, and the image must be extracted from table 1 and joined with the data from table 2.

Step-by-step guide to parse and format this in Kodular:


:white_check_mark: Step 1: Convert JSON to list

Use the Web Component or JSONTextDecode block to decode the outer array.

set rawData to get responseContent
set parsedList to JSONTextDecode rawData

Now parsedList is:

["1749681227813", "Botella", "150", "100", "https://i.ibb.co/nqXYmMVF/f432e564f944.jpg", "166", "1749774030030", ...]

:white_check_mark: Step 2: Create lists to store data separately

In Kodular, create the following empty lists:

  • IDList
  • NameList
  • PriceList
  • StockList
  • ImageList
  • CodeList

:white_check_mark: Step 3: Loop through data

Use a for each number loop from 1 to length of list, step by 6 (because each item has 6 values):

for each number i from 1 to length of list parsedList by 6:
    add item select list item list parsedList index i      → to IDList
    add item select list item list parsedList index i + 1  → to NameList
    add item select list item list parsedList index i + 2  → to PriceList
    add item select list item list parsedList index i + 3  → to StockList
    add item select list item list parsedList index i + 4  → to ImageList
    add item select list item list parsedList index i + 5  → to CodeList

:white_check_mark: Step 4: Now use these lists

You now have:

  • IDList = ["1749681227813", "1749774030030", "1749946948757"]
  • NameList = ["Botella", "miel", "remera"]
  • PriceList = ["150", "1 500", "500"]
  • StockList = ["100", "20", "4"]
  • ImageList = [URL1, URL2, URL3]
  • CodeList = ["166", "199", "232"]

:warning: Fix Potential Error: ["[ ... ]"] is a string, not a list

If your database sends the data like:

["[\"1749681227813\", \"Botella\", ...]"]

Then you need to:

  1. Get the first item from the list.
  2. Decode that string as JSON again.

Example in Kodular:

set tempString to select list item list (JSONTextDecode responseContent) index 1
set finalList to JSONTextDecode tempString

Now finalList will be the flat list of 18 items.


:white_check_mark: Final Structure for 3 Products (example)

ID Name Price Stock Image URL Code
1749681227813 Botella 150 100 https://i.ibb.co/nqXYmMVF/f432e564f944.jpg 166
1749774030030 miel 1 500 20 https://.ibb.co/1YbDHtx6/726d306ae6fd-jpg 199
1749946948757 remera 500 4 https://i.ibb.co/DT654xq/7739944c3b25.jpg 232

do you want a Kodular block picture?

If you can and have the time, I’d love to. If not, what you’ve helped me with is perfect! Thanks!
.

1 Like