Help in dealing with json data

Hi everyone

I need help in how to deal with JSON data

I tried a lot to access each stime + etime of each of the 16 objects but i failed i only managed to access the 1 one.

the json variable data is

{"0":"10:00:00","stime":"10:00:00","1":"10:30:00","etime":"10:30:00"}{"0":"10:30:00","stime":"10:30:00","1":"11:00:00","etime":"11:00:00"}{"0":"11:00:00","stime":"11:00:00","1":"11:30:00","etime":"11:30:00"}{"0":"11:30:00","stime":"11:30:00","1":"12:00:00","etime":"12:00:00"}{"0":"12:00:00","stime":"12:00:00","1":"12:30:00","etime":"12:30:00"}{"0":"12:30:00","stime":"12:30:00","1":"13:00:00","etime":"13:00:00"}{"0":"13:00:00","stime":"13:00:00","1":"13:30:00","etime":"13:30:00"}{"0":"13:30:00","stime":"13:30:00","1":"14:00:00","etime":"14:00:00"}{"0":"14:00:00","stime":"14:00:00","1":"14:30:00","etime":"14:30:00"}{"0":"14:30:00","stime":"14:30:00","1":"15:00:00","etime":"15:00:00"}{"0":"15:00:00","stime":"15:00:00","1":"15:30:00","etime":"15:30:00"}{"0":"15:30:00","stime":"15:30:00","1":"16:00:00","etime":"16:00:00"}{"0":"16:00:00","stime":"16:00:00","1":"16:30:00","etime":"16:30:00"}{"0":"16:30:00","stime":"16:30:00","1":"17:00:00","etime":"17:00:00"}{"0":"17:00:00","stime":"17:00:00","1":"17:30:00","etime":"17:30:00"}{"0":"17:30:00","stime":"17:30:00","1":"18:00:00","etime":"18:00:00"}__16

i put __ and the count so i know how many objects i can get but i'm still stuck in first step of accessing each data of those any help in what i shall add or do in these blocks below.

i know i need a new [ for each number block ] but for now i just let's say want to access object number 12 or 13.

{"0":"15:30:00","stime":"15:30:00","1":"16:00:00","etime":"16:00:00"}{"0":"16:00:00","stime":"16:00:00","1":"16:30:00","etime":"16:30:00"}

here's the block

thank you in advance.

They should be separated with commas, and they should be in one list, so the correct JSON should be:

[{"0":"10:00:00","stime":"10:00:00","1":"10:30:00","etime":"10:30:00"},{"0":"10:30:00","stime":"10:30:00","1":"11:00:00","etime":"11:00:00"},{"0":"11:00:00","stime":"11:00:00","1":"11:30:00","etime":"11:30:00"},{"0":"11:30:00","stime":"11:30:00","1":"12:00:00","etime":"12:00:00"},{"0":"12:00:00","stime":"12:00:00","1":"12:30:00","etime":"12:30:00"},{"0":"12:30:00","stime":"12:30:00","1":"13:00:00","etime":"13:00:00"},{"0":"13:00:00","stime":"13:00:00","1":"13:30:00","etime":"13:30:00"},{"0":"13:30:00","stime":"13:30:00","1":"14:00:00","etime":"14:00:00"},{"0":"14:00:00","stime":"14:00:00","1":"14:30:00","etime":"14:30:00"},{"0":"14:30:00","stime":"14:30:00","1":"15:00:00","etime":"15:00:00"},{"0":"15:00:00","stime":"15:00:00","1":"15:30:00","etime":"15:30:00"},{"0":"15:30:00","stime":"15:30:00","1":"16:00:00","etime":"16:00:00"},{"0":"16:00:00","stime":"16:00:00","1":"16:30:00","etime":"16:30:00"},{"0":"16:30:00","stime":"16:30:00","1":"17:00:00","etime":"17:00:00"},{"0":"17:00:00","stime":"17:00:00","1":"17:30:00","etime":"17:30:00"},{"0":"17:30:00","stime":"17:30:00","1":"18:00:00","etime":"18:00:00"}]

1 Like

I do not see you decode the JSON data into App Inventor values, if you do not decode them, it would be the same as selecting an item from a string.

Also, what is this?

Varius ways to work with json according to needs

2 Likes

Thank you i will try that i guess it's will fix my issue easily never heard of that block jsondecode with dictionaries.

1 Like

The best way I suggest you to deal with json objects or array is using extension which use org.json . Previously, I used to use Jerin's JsonUtils extension but due to some limitations of the extension, I have built one.

Download JsonParser extension


For me it is easier to work with dictionary blocks, all you have to do is to understand json's structure.

2 Likes

JsonObject starts with { and JsonArray starts with [ .. Easy way to figure out Array & Object.

2 Likes

I know that :slight_smile: I meant depending the structure you can use the proper block

1 Like

Yeah. ....

1 Like

Thank you Dora,

Now i got them fixed

3 Likes

I also used to use dictionaries to parse json, using mohammad tamer's extension to convert json to dictionaries as I remember.

Later, when I used some method of org.json while creating my baserow extension, I realised it is easier to understand, so had started using JsonUtils extension by Jerin. Later, I created own extension and started using it. :sweat_smile::sweat_smile:

1 Like