Import a json file into a listview or spinner

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

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


Please export your project and post it here.

Try this

halflosse.aia (2.1 KB)

Strangely, the Web component returns a script in html...
Capture

That is not JSON.

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

@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

What is the url now, and have you revised the output of the file to return just JSON and not javascript?

the new url is now:
http://schulehaho.bplaced.net/stationen2.txt
kindly regards

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

If your JSON is formed as above:

image

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

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