Basically I followed this
https://ai2.appinventor.mit.edu/reference/other/json-web-apis.html
For the example, the sample JSON is different from the JSON response from the API I use.
The API JSON is like this:
{
"odata.metadata": "http://datamall2.mytransport.sg/ltaodataservice/$metadata#BusStops ",
"value": [
{
"BusStopCode": "01012",
"RoadName": "Victoria St",
"Description": "Hotel Grand Pacific",
"Latitude": 1.29684825487647,
"Longitude": 103.85253591654006
},
{
"BusStopCode": "01013",
"RoadName": "Victoria St",
"Description": "St. Joseph's Ch",
"Latitude": 1.29770970610083,
"Longitude": 103.8532247463225
},
and so on...
However, for the "get value for key" im not sure what to put for get value for key because BusStopCode doesn't work, I know theres like value is part of what im figuring it out because when i put value everything after value and : comes out so thanks for the help!
TIMAI2
August 26, 2024, 3:11pm
2
You can return all the values as a list:
Explain a little about what you want to do with the dataset once you get it back?
1 Like
the coordinates will be used to be place as a point on the map, while the Bus Stop Code, Road Name and Description will be placed in a button, one bus stop per button. When the user selects the button it brings them to another page unique to the bus stop
and where do i find the "Do it Result" is it found on another website.
TIMAI2
August 27, 2024, 9:45am
4
You can use Do it in the blocks editor when you connect your project to the companion app
ABG
August 27, 2024, 12:27pm
5
I don't see a bus route field in your data model.
Or are you using the road name field for that and the buses can't turn?
TIMAI2
August 27, 2024, 12:28pm
6
BusStopCode is the first element of the list.
ABG
August 27, 2024, 12:41pm
7
Or is the bus route derivable from the bus stop code by clipping the first two digits?
FYI I am making a bus arrival app.
So basically the user selects a bus stop > screen will open containing bus service and its arriving time.
As for this API, the road name is just extra info, the main thing is that I need to list all the bus stops nearby for the user to select
bus route and arrival timings is a seperate api
ABG
August 27, 2024, 2:50pm
9
You will need current location of the phone (make sure you have a gps fix), a distance limit for "nearby", and one of the "closest" approaches from
Besides searching this board for "closest", look for "geofence".
The tabular format derived earlier in this thread forms a good basis for such iteration.
TIMAI2
August 28, 2024, 12:32pm
11
This
should be the local variable json
ABG
August 28, 2024, 1:25pm
12
Using the name 'json' for that dictionary extracted from the responseContent tripped you up.
A more appropriate name would have been 'responseDictionary' to show where it came from and what data type (dictionary) it is.
A dictionary is not a JSON string, and a JSON string is not a dictionary.
One is a piece of text with brackets and punctuation following JSON syntax.
The other is an internal memory structure wired for use with the dark blue dictionary blocks.
TIMAI2
August 28, 2024, 2:41pm
13
Yes, I should have used dict
in my example