Parsing JSON for use in Listbox

Hello, I am fairly new to Xojo and I am working on a desktop app that will provide some information from our Filemaker Server. Where I am having trouble is when trying to parse out the bit of information I want from the JSON I’m getting from the FMServer.

Here is an example of the response.

[code]{
“response”: {
“data”: [
{
“fieldData”: {
“RelatedCompany”: “Example Company.”,
“ClientStatus”: “Active”
},
“portalData”: {},
“recordId”: “1111”,
“modId”: “11”
},

        }
    ]
},
"messages": [
    {
        "code": "0",
        "message": "OK"
    }
]

}[/code]

At this point in time, the only information I’m really wanting is the “RelatedCompany” and I would like to display that information in a Listbox named Listbox1. “data” has 100 records in it and I want to display each one of them “RelatedCompany” value in the Listbox.

I have tried a number of variations of For each…Next statements loops but continue to get errors so I decided to reach out for help. I know this is solvable and probably simple but I’m just not seeing it.

Thanks in advance.

dim json as new JSONItem( jsonString )
dim response as JSONItem = json.Child( "response" )
dim data as JSONItem = response.Child( "data" )
for row as integer = 0 to data.Count - 1
  dim fieldData as JSONItem = data.Child( row ).Child( "fieldData" )
  dim relatedCompany as string = fieldData.Value( "RelatedCompany" )
next

Or something like that.

@Kem Tekinay Thank you for the reply. I’m not entirely sure I understand. Are you suggesting that I would need to create a new JSON item from the JSON data provided by my server? what is the value of jsonString? is it the variable that I have created that the JSON data currently live in?

Here are my first few lines of code which might help make more sense of things. Sorry, should have provided that originally.

[code]Dim jsonData As Text

// Convert the content returned from the API MemoryBlock to Text
jsonData = Xojo.Core.TextEncoding.UTF8.ConvertDataToText(content)

// Create a Dictionary to hold the JSON data once Parsed
Dim jsonDict As Xojo.Core.Dictionary
// Parse the JSON result into a Dictionary
jsonDict = Xojo.Data.ParseJSON(jsonData)

Dim response As Xojo.Core.Dictionary = jsonDict.Value(“response”)
[/code]

again my goal is to capture the value of what is in “RelatedCompany” and place it in a Listbox for each of the entries in “data”.

Thanks again.

Yes, jsonString is the received JSON.

I used the classic framework, but your code is fine. Just follow the data to what you want keeping in mind that arrays are stored as Auto(). Use the code I posted as a guideline.