How to put the json formatted data from web server to MIT label text?

115 views
Skip to first unread message

Xiaomy Redmii

unread,
Nov 13, 2018, 9:57:06 AM11/13/18
to MIT App Inventor Forum
This are the data, I am confused on doing this. Need help thank you :)

{"Distance" : 166,"Temperature" : 31.00,"Humidity" : 74.00}

Xiaomy Redmii

unread,
Nov 13, 2018, 10:19:54 AM11/13/18
to MIT App Inventor Forum

screenshot_20181113_231850.png


Xiaomy Redmii

unread,
Nov 13, 2018, 10:22:19 AM11/13/18
to MIT App Inventor Forum
I know how to send the data from web server to MIT app inventor in html format but I tried to do the same in JSON formatted text and doesn't retrieve the data. I want it also to separate the data not like the previous one that accepting all in one label text. 

Xiaomy Redmii

unread,
Nov 13, 2018, 10:37:18 AM11/13/18
to MIT App Inventor Forum
Or there is no need to use a JSON format?

Ghica

unread,
Nov 13, 2018, 10:49:32 AM11/13/18
to MIT App Inventor Forum
How about this:

Snap1.png


Cheers, Ghica

Ghica

unread,
Nov 13, 2018, 10:56:34 AM11/13/18
to MIT App Inventor Forum
By the way: the label looks something like this:

Distance: 166
Humidity: 74
Temperature: 31

Cheers, Ghica.

Xiaomy Redmii

unread,
Nov 13, 2018, 11:02:47 AM11/13/18
to MIT App Inventor Forum
wow
only one label text? :) 

Ghica

unread,
Nov 13, 2018, 11:14:28 AM11/13/18
to MIT App Inventor Forum
That is what you wanted, right?
I am nice today, here is the .aia

Cheers, Ghica
distance.aia

Xiaomy Redmii

unread,
Nov 13, 2018, 11:18:46 AM11/13/18
to MIT App Inventor Forum
awww thanks ghica :) I already manually copy it hehe super thanks!

Xiaomy Redmii

unread,
Nov 13, 2018, 11:32:04 AM11/13/18
to MIT App Inventor Forum
got error on blocks

Xiaomy Redmii

unread,
Nov 13, 2018, 11:35:42 AM11/13/18
to MIT App Inventor Forum
line 5 no matching syntax-rule

Xiaomy Redmii

unread,
Nov 13, 2018, 11:42:16 AM11/13/18
to MIT App Inventor Forum
its not allowing me to publish the app

Xiaomy Redmii

unread,
Nov 13, 2018, 11:54:11 AM11/13/18
to MIT App Inventor Forum
I removed the 2 errors and still not publishing

Xiaomy Redmii

unread,
Nov 13, 2018, 12:00:15 PM11/13/18
to MIT App Inventor Forum

screenshot_20181114_005936.png


Ghica

unread,
Nov 13, 2018, 12:09:50 PM11/13/18
to MIT App Inventor Forum
I have No club.
Can you post your .aia?
Cheers, Ghica

Ghica

unread,
Nov 13, 2018, 12:11:23 PM11/13/18
to MIT App Inventor Forum
I ment: no clue.

Xiaomy Redmii

unread,
Nov 13, 2018, 5:37:39 PM11/13/18
to MIT App Inventor Forum
good morning :) 
json.aia

Xiaomy Redmii

unread,
Nov 13, 2018, 5:43:03 PM11/13/18
to MIT App Inventor Forum
maybe forgot to call the web?

Xiaomy Redmii

unread,
Nov 13, 2018, 5:48:05 PM11/13/18
to MIT App Inventor Forum
I finally publish it by dragging the call function for web

Xiaomy Redmii

unread,
Nov 13, 2018, 6:00:53 PM11/13/18
to MIT App Inventor Forum
another problem was it's not updating based on the webserver

Ghica

unread,
Nov 14, 2018, 5:42:22 AM11/14/18
to MIT App Inventor Forum
Hi Xiaomi,
(your good morning was my midnight...)
You have attached your ,aia, but that looks all too familiar to me... :-(
But what is your problem now?
Were is the part that retrieves data from the web?
Cheers, Ghica
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

Xiaomy Redmii

unread,
Nov 14, 2018, 9:49:51 AM11/14/18
to MIT App Inventor Forum
I don't know how I can update the data from the webserver using json file (blocks) of yours (aia). The file I attached was a code block to send data on the app but it is in normal format (HTTP for)
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

Xiaomy Redmii

unread,
Nov 14, 2018, 9:56:49 AM11/14/18
to MIT App Inventor Forum

screenshot_20181114_225344.png


Ghica

unread,
Nov 14, 2018, 10:04:36 AM11/14/18
to MIT App Inventor Forum
I do not understand what is difficult about this.
In the Web.GotText, you set global jsondata = responseContent and then you call setLabel

But it assumes of course that you receive json from your webserver. If that is not the case, could you maybe show an example of what you receive?
Cheers, Ghica.

Xiaomy Redmii

unread,
Nov 14, 2018, 10:08:43 AM11/14/18
to MIT App Inventor Forum
I receive the same output you've expected earlier

Xiaomy Redmii

unread,
Nov 14, 2018, 10:25:52 AM11/14/18
to MIT App Inventor Forum

screenshot_20181114_232524.png


Abraham Getzler

unread,
Nov 14, 2018, 12:08:45 PM11/14/18
to MIT App Inventor Forum
I don't know how I can update the data from the webserver

To continually update data from a Web server, put your
Web Get request in a Clock Timer.

The Clock component is in the Designer Sensors Drawer.

ABG
 

Xiaomy Redmii

unread,
Nov 14, 2018, 3:58:20 PM11/14/18
to MIT App Inventor Forum
even a JSON formatted text will be allow to use that function?

Ghica

unread,
Nov 14, 2018, 5:16:34 PM11/14/18
to MIT App Inventor Forum
I am not sure what you mean,
What ABG says, is that you can use a clock function, and put the web request in the clock.Timer event.
Everything else should stay the same, and assuming that your server wil send json formatted text, you will see the label update every second.
Cheers, Ghica.

Xiaomy Redmii

unread,
Nov 14, 2018, 7:03:21 PM11/14/18
to MIT App Inventor Forum
it's not updating :(
I followed your blocks

Xiaomy Redmii

unread,
Nov 14, 2018, 8:12:38 PM11/14/18
to MIT App Inventor Forum
I also change the url of the web so that it can be align with my web server (esp8266)

Abraham Getzler

unread,
Nov 14, 2018, 8:29:51 PM11/14/18
to MIT App Inventor Forum
I followed your blocks

Show us

ABG 
Message has been deleted
Message has been deleted

Xiaomy Redmii

unread,
Nov 14, 2018, 8:48:54 PM11/14/18
to MIT App Inventor Forum

bug.png


here's the block screenshot only I can't send the file I think there's a bug here

Abraham Getzler

unread,
Nov 14, 2018, 9:54:17 PM11/14/18
to MIT App Inventor Forum

Xiaomy Redmii

unread,
Nov 15, 2018, 12:31:42 AM11/15/18
to MIT App Inventor Forum
it doesn't work

Xiaomy Redmii

unread,
Nov 15, 2018, 12:56:17 AM11/15/18
to MIT App Inventor Forum

here.png


Ghica

unread,
Nov 15, 2018, 1:24:58 AM11/15/18
to MIT App Inventor Forum
Where is the clock????
Do you get the right values once? Which would mean that the connection works alright?
Cheers, Ghica

Xiaomy Redmii

unread,
Nov 15, 2018, 1:41:01 AM11/15/18
to MIT App Inventor Forum
I didn't try the clock so far 
the values only print the text in global jsondata and not the data from web server

Xiaomy Redmii

unread,
Nov 15, 2018, 1:50:58 AM11/15/18
to MIT App Inventor Forum

12.png

screenshot_20181115_144722.png


Xiaomy Redmii

unread,
Nov 15, 2018, 2:43:02 AM11/15/18
to MIT App Inventor Forum
what was the possible problem then?

Xiaomy Redmii

unread,
Nov 15, 2018, 8:29:06 AM11/15/18
to MIT App Inventor Forum
help please :)

Xiaomy Redmii

unread,
Nov 15, 2018, 9:42:30 AM11/15/18
to MIT App Inventor Forum
need your help pls

SteveJG

unread,
Nov 15, 2018, 10:11:09 AM11/15/18
to MIT App Inventor Forum
This might work

UseAClock.PNG


Use a Clock to continually update.  Perhaps set Clock  TimeInterval to 30 seconds (30000 ms).
In the Web1.GotText   you need something like:

set jsondata to responseContent    because you need this in setlabel
setLabel                                           because you need to parse the json 

Will this work?   No idea... try it and then experiment.  You must have a Clock to continually update and so far, you have not shown any blocks showing you have done this. Instead of the Button (which only will display the temperature data once you need a Clock.  Or, you could press the Button each time you want a new reading.

Regards,
Steve              



Xiaomy Redmii

unread,
Nov 15, 2018, 11:15:07 AM11/15/18
to MIT App Inventor Forum
okay sir trying :)

Xiaomy Redmii

unread,
Nov 15, 2018, 11:22:55 AM11/15/18
to MIT App Inventor Forum
how to put that setlabel?

Xiaomy Redmii

unread,
Nov 15, 2018, 11:29:11 AM11/15/18
to MIT App Inventor Forum
setlabel in the lower part? I'm confused

SteveJG

unread,
Nov 15, 2018, 11:49:43 AM11/15/18
to MIT App Inventor Forum
call setLabel Xiaomy  is the call to your label parsing routine. The block needs to follow set jsondata to responseContent

What have you tried?  Just try some code and experiment.  

Think about the free programming course described below to help you understand the suggestions Forum members provide? Show your revised blocks here in the Forum.


Here are some resources to help you learn to use the AI2 tools  It is very difficult to help with some slightly advanced programming techniques when a beginning developer has NOT done any tutorials or taken any training.  Learning on your own is difficult but there are tutorials that help.

A very good way to learn App Inventor is to read the free Inventor's Manual here in the AI2 free online eBook   http://www.appinventor.org/book2 ... the links are at the bottom of the Web page.  The book 'teaches' users how to program with AI2 blocks.

There is a free programming course here http://www.appinventor.org/content/CourseInABox/Intro  and the aia files for the projects in the book are here:  http://www.appinventor.org/bookFiles  

How to do a lot of basic things with App Inventor are described here:  http://www.appinventor.org/content/howDoYou/eventHandling  .


Xiaomy Redmii

unread,
Nov 20, 2018, 7:03:19 AM11/20/18
to MIT App Inventor Forum
I postpone the building of the block because I still not get any response from the web server and it's still hard for me to connect it there

Ghica

unread,
Nov 20, 2018, 8:05:26 AM11/20/18
to MIT App Inventor Forum
Xiaomi,
It is hard to understand your strategy of developing this. First things first!!
Make sure that your basic connection works. The rest is just bit shifting that always can be solved.

A few days ago, you had these blocks:

screenshot_20181114_225344.png

Now, if you run this app, assuming the ESP is running, and you press Button1, WHAT do you see in Label1.Text??
Copy it here in the forum!
Cheers, Ghica.

Mark Donadillo

unread,
Nov 20, 2018, 8:29:07 AM11/20/18
to MIT App Inventor Forum
distance (1).aia

Xiaomy Redmii

unread,
Nov 22, 2018, 8:46:58 AM11/22/18
to MIT App Inventor Forum
pls need your help in my new topic
Reply all
Reply to author
Forward
0 new messages