Fetching information for a JSON php.-file

21

Hello,

We are trying to fetch a JSON-object and display it using a list view. However, we struggle with parsing the JSON-object. Please have a look at the attached image. If we’ve understood correctly, Thunkable interprets the JSON-object from the GET-request as a string, which has to be converted to an object using the corresponding function. That one is not supported by the “for each in”-function. The JSON-object as is now will to be parsed by the “for each item j in…”-function, which at the moments moves trough the JSON-object character by character.

What we are trying to accomplish, is getting the JSON from the server, display the keys in a list view, have the user tap one and the select the appropriate value from the JSON-object which is in turn sent back to the server via a new GET-request.

Any help would be greatly appreciated.

Hi there. Do you have a picture of the raw output that your JSON object is in? This will help us understand what the appropriate parsing method might be.

Albert

Hello,

First, you need to check if there is any response from the server at all.

webapi

If the answer is received, then it is parsed

webapi2

Good morning,

The JSON looks as followed:

{“foo”:1,“bar”:2,“biz”:3,“baz”:4,“bang”:5}

We want to loop trough it as display each key as a button in the list viewer. When pressed, the function should return the associated value. As far as we’ve understood, the get property-function only reads one value by giving it the key.

Thank you for your help!

Ida

Thank you! We will try this solution too.

Ida

In Thunkable X, when parsing JSON, I recommend converting JSON data into a string. In your case, everything is very simple:

  1. Delete all parentheses {} and characters " from JSON string.
  2. Create a list using the “make list from text with delimiter” block. Use a comma as a delimiter.
  3. Organize a loop in the list to get the functionality you need.