'get object from json' issue

Hi all

I’m experienced in app inventor 2 but new to thunkable.

I am trying to read a json which is generated from php script on my website when i press a button.

i am using web_api GET and if i put the response directly in to label_text it shows the whole json so it works.

but when i use ‘get property of object’ and ‘get object from json’ from the response, the first response always gives a network request failed error. if i press the button again then it works fine and works everytime after that.

if i restart the app, the first attempt always gives the network request failed error. it then works fine if i press the button again.

any help would be appreciated or if this is a bug

thanks

Hi, :wave: & Welcome to Thunkable Community! :tada:

Since you’re an experienced user of AI2, you would soon catch-up with Thunkable too :upside_down_face:


Try to set this block image to a variable, and then attach the variable to the ‘get property’ block.

See if it works now.
Thanks!

2 Likes

Hey @captainzee9999jf, we also have this great tutorial series on APIs which @simran developed last year that will help get you up to speed with Thunkable X too!

4 Likes

Thanks guys. Will watch the video and try your suggestion

unfortunately the variable idea didnt work, it was still bringing up the network request failed

Ok, can you make sure your internet is working properly?
Also please provide your device details with Android/iOS version.

Thanks!

1 Like

The internet is definitely working ok. I’m using a samsung s9+ with android version 10.

I did get the weather app working that was shown in the video above but that now crashes the thunkable live app.

Thanks for any help you can give

This is the output from the json when I access it through the browser

That would be just a single object?
Can you provide a share link?

1 Like

The URL returns:
{"name":"Perrin","darkmark":"ZBDVBS"}

image

Did you try removing the IF statements and just having the set label to darkmark?

Just this block inside of the Web_API1 block:
image

1 Like

thank you for all your suggestions but i think i have found the issue. I did originally try it without the if statement and still had the same issue.

the web_API ‘set url’ appears to need a variable either joined to the url text. (blank text box will not do it) or the url to be got from a variable. I copied the weather app from the video above and modified my app to match. Then slowly took off parts I didnt need till it started to fail. Removing the variable input caused the issue.

the pic below shows the code working fine

(this test php i created requires no api key or username/password)

i assume there is a bug or some restriction i am unaware of

1 Like