String manipulation

Hello szymekkart250

Does your App have to download the questions from a web page? If it does have to, is that website yours? If it is yours, you can collect a CSV file instead of HTML. If you don't have to download you can store a CSV file in the App, or send me that file and I can convert it into a Blocks List.

I download this file from URL. A couple of replies above there is the process of downloading the json. Thanks for Your help!

I download this file from URL. A couple of replies above there is the process of downloading the json.

What I mean is - does the App only ever perform the download once, only use this data?

The idea is that I download the data once, when the user want to start a quiz game. Later I want to display this data on the screen. So yeah, somehow I can tell that it performs the download once, but there can be a second download when sbd want to play another game.

So it sounds as though you have control of the online data - so why not download a CSV file that has no formatting issues?

@ChrisWard How do I get a CSV file? Is it done by using the "Web.GotText" and processing the "responseContent"? I havn't worked with it so far. Thanks!

Is it your own website?

No, this was a general question following the discussion here I'm interested in.

So you can only get a CSV if the website owner makes one available.

1 Like

@ChrisWard Ah, thank you!

Can you direct the Web1 GotText responseContent to a temporary Text Box, copy it, send it to yourself via email and post it here as a text file? Or alternatively let us have the URL.

Here is a sample url

https://opentdb.com/api.php?amount=10&type=multiple

It will return different questions every time

1 Like

@TIMAI2 Oh, thanks, I'm going to test it/make first experience with it later on.

Would be good to hear from ABG, he is our JSON Guru.

1 Like

Hi all, I just dropped into this thread.

Without any coding, here are my thoughts ...

  • The JSON looks okay.
  • The web markup in the questions suggest to me that maybe plopping the questions into a HTML Label or WebViewer would let them do their appearance thing without having to clean out any markup.
  • JSON Strings turned into objects have the right to come back in a different order than the original JSON strings, since the dictionary internals are supposed to be accessed by key.
  • I see no need for bracket and quote removal in answers, if they are manipulated as lists and offered for display as ListView Elements.
  • a list append and a list randomizer call would be needed before loading a ListView Elements with answer options. (I have one in stock, if any one needs.)

I could wire up a solution, if any one has a recent .aia to build on.

I took a first whack at the project, and discovered that the answers might have markup also, so the ListView is not up to the task.

I would have to rework this to use buttons, and restrict the total number of possible answers to the length of my button list.

Capture Correct ListView is inadequate opentdb.aia (5.5 KB) Wrong

I managed to remove the internal answer markup using the Web1.HTMLDecode block.
With no markup showing, the ListView was up to the task.

Capture Correct Decoded opentdb.aia (6.0 KB) Wrong
(I figured, if HTMLEncode adds markup, then HTMLDecode must remove markup.)

This should be my final version .

2 Likes

(added to FAQ)

1 Like

@ABG Thank you very much for this detailed presentation. I've got a first idea of how to use JSON stuff along with the web component and its blocks that I didn't use so far. I've played around a bit and additionally found an example in the web http://sparse-dense.blogspot.com/2020/03/decoding-json-by-using-new-dictionaries.html, to my opinion worth to put an eye on it, as well as a YT video by @ewpatton Evan Patton https://www.youtube.com/watch?v=8rhw7JIB9R0 :slight_smile:

1 Like