Hi!
I have here an json file wich I want to import in a listview or spinner.
The json file is located in the web:http://schulehaho.bplaced.net/sender.html
I want to insert from this file the text: http://onair.krone.at/kronehit.mp3 and http://mp3stream1.apasf.apa.at:8000/
I have tried the following code:
But my listview is alway empty.
Hope somebody can help.
kindly regards
ABG
January 5, 2021, 11:12pm
2
Start with using responseContent instead of responseCode.
Here is the JSON you get:
{"sender":["http://onair.krone.at/kronehit.mp3","http://mp3stream1.apasf.apa.at:8000/"]}
Do you want your ListView to contain the two Elements
Set ListView1.Elements to
lookup in pairs(key('sender'),pairs(Web1.JSONDecode(responseContent)),notfound(create empty list))
in your Web1.GotText even
Thanks for your reply.
I have change now the following:
But when I press the button I will get the following error message:
The second argument to foreach is not a list. The second argument is "<script>"
It seems the webfile is not correct. when I open the source of the url I will get:
Hope someone have an idea how I can get a real json file which I can use with appinventor.
kindly regards
ABG
January 6, 2021, 1:50am
4
Please export your project and post it here.
ABG
January 6, 2021, 2:27am
6
Strangely, the Web component returns a script in html...
That is not JSON.
TIMAI2
January 6, 2021, 10:49am
7
In a computer web browser the url returns a JSON:
{"sender":["http://onair.krone.at/kronehit.mp3","http://mp3stream1.apasf.apa.at:8000/"]}
Explain what you want to do with the two elements?
Thanks for your answer.
I want to add these two elements in a spinner for selecting for an audiostream.
kindly reagards
TIMAI2
January 7, 2021, 6:01pm
9
@ABG is right, the web url being called is malformed and not returning a JSON, it is setup to write text to an html page. However, with replacement blocks it is possible to get at the content
Example blocks
Example screen
thanks for the answer.
I have done an update of my json file.
I use now:
{sender:[{text:krone,url:'http://onair.krone.at/kronehit.mp3 '},{text:hit, url:'http://mp3stream1.apasf.apa.at:8000/ '}]}
I want not two list. In one list I want to insert all text elements and in the other list all url elements.
In my example:
list1: krone, hit
list2: http://onair.krone.at/kronehit.mp3 , http://mp3stream1.apasf.apa.at:8000/
Hope someone can still help me here again.
kindly regards
TIMAI2
January 7, 2021, 8:48pm
11
What is the url now, and have you revised the output of the file to return just JSON and not javascript?
TIMAI2
January 7, 2021, 9:04pm
13
Your JSON should look like this:
{"sender":[{"text1":"krone","url1":"http://onair.krone.at/kronehit.mp3"},{"text2":"hit", "url2":"http://mp3stream1.apasf.apa.at:8000/"}]}
Thanks.
I have changed now the url.
kindly regards
TIMAI2
January 7, 2021, 9:10pm
15
If your JSON is formed as above:
TIMAI2
January 7, 2021, 9:15pm
16
You didn't add the double quotes....
Thanks a lot for your answer.
It seems I don't need the double quotes - or?
Also I tried it with only text and url.
In my code it works.
Thanks for your help.
kindly regards
Hi!
I see. When I do a validation of the file I must use the double quotes. Thanks for the information.
I have changed now again the url.
kindly regards
TIMAI2
January 7, 2021, 9:40pm
19
For a correctly formatted JSON, the keys must be in double quotes
{"key":value}
If the value is a number it does not need quotes, but it makes sense to put a string in quotes as well.
Thanks for the information.
kindly regards