Hi,
I'm making a trivia app for an assignment and the only thing I'm struggling on is actually getting the questions and answers loaded in. There are three different json files for three different difficulties, but as an example this is the hard difficulty file.
https://opentdb.com/api.php?amount=20&difficulty=hard&type=multiple&encode=url3986
My teacher says to use Web.UriDecode to decode the questions but I am unsure how to actually extract the data and load it in to appinventor, let alone have it cycle through the questions.
If anyone knows how to go about this, I'd be very grateful
UriEncode and UriDecode convert text from/to UTF-8. Individual inputs to URL parameters do not accept characters such as spaces and ampersands. Therefore, we use UTF-8 to convert them into "special" characters, such as &
for ampersands.
In your case, you should use JsonTextDecodeWithDictionaries
instead. This will convert the JSON text into App Inventor values of dictionaries and/or lists.
Do you have any advice on how to get the app to run through the questions, as well as setting things to the correct and incorrect answers as options?
When I try to go about it the way I would think to, I get this "Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference
Note: You will not see another error reported for 5 seconds."
You might want to learn some basic JSON, and find a JOSN parser tool. For me I use http://json.parser.online.fr/.
Please show your blocks, since there can be a lot of reasons for this (the most common way is to right-click the blocks, and select Download Blocks as Image).
As per this suggestion, I've edited the code to look like this:
I am having issues in the app, as you can see below when I load a question it doesn't add the correct answer, it only shows incorrect answers all as one answer.
(Canned Reply: ABG- Export & Upload .aia)
Export your .aia file and upload it here.
Also, why do you load questions from a file after you got a response from the Web?
Why would you need both?
Trivial_Pursuit.aia (21.1 KB)
It only pulls the questions from the files if the response code isn't 200, meaning there's no internet connection. It's so it can be used offline as well, it was a requirement of my assignment.
You have multiple instances of TinyDB under different names, but their underlying Namespaces are all TinyDB1.
That means any two of them with the same tag in them are dealing with the same value.
You failed to append the correct and incorrect values when building the answer list before its shuffle.
Here is a corrected procedure:
P.S. These blocks can be dragged directly into your Blocks Editor workspace.
I have updated the code to fix appending to the list, and mostly changed my databases namespaces.
I am now just having an issue with the saving scores function, as you can see below it keeps getting full of incrementing """". If you know how to solve this issue that'd be great.
Trivial_Pursuit (1).aia (23.0 KB)
Looking at your app, I am going to guess that you are working in a team to build this app, and the team members don't talk to each other to agree on common things like TinyDB tags and values for saving scores.
You used 4 Screens for an app that only needed one Screen, maybe because you were forced to use 4 people in your team and you had no other idea on how to keep them out of each others' hair?
Your app resembles the Howard Brothers trying to get their car to the auto repair shop:
- one brother is behind the car, pushing
- another brother is in the car, running the engine
- the third brother is driving the tow truck pulling the car.
This app is more than an exercise in coding.
It's an exercise in Leadership, of taking responsibility for quality control over all the parts of your app.
Your score saving mechanisms are fractured, with different ideas of:
- how to pass scores from screen to screen (TinyDB tag/value AND start value? No!)
- choice of TinyDB tag for the score (I saw at least 2 tags)
- choice of single numerical value or a list of values?
- Inclusion of text prefix in the TinyDB score value?
You must go on a hunt through all the screens for dissident ideas on the score storage scheme, and erase them.
Be ruthless.
unlisted at OP's request