Parsing JSON to ListBox

Hello,

I’m new in Xojo and I’m trying to parse one JSON to ListBox following examples found in this forum. I think I don’t understand very well how Xojo works with these kind of files.

I’ve one Window with two objects, one TextArea to view the output and one ListBox. In the listbox I’ve 4 columns and my goal es parse some key values from JSON to columns.

I need a little help parsing the JSON to columns so I appreciate some help pointing me in the right directorio to parse. This is the code I’ve:

Var socket1 As New HTTPSocket
Var jsonData As String = socket1.Get("myurl", 30)

Var apiResponse as new JSONItem(jsonData)

Var results as JSONItem = apiResponse.child("data")
Var n as JSONItem
Var author() as string
Var title() as string
Var description() as string
Var i as integer

for i = 0 to results.count-1
  n= results.child(i)
  author.append n.value("author")
  title.append n.value("title")
  description.append n.value("description")
  
  ListBox1.AddRow(title)
next
outputApi.Text = apiResponse.ToString

Hi Jose,

welcome to the forum. Please post an example of your JSON. Where do you have problems?

thank you for your reply.

I’ve not problem with the JSON itself. The problem is parse it to listbox columns at once.

Example of JSON file:

{
   "meta":[
      {
         "recordID":"762",
         
      },
      {
         "recordID":"1365",
        
      },
      {
         "recordID":"1715",
        
      },
      {
         "recordID":"4003",
        
      },
      {
         "recordID":"4508",
        
      }
   ],
   "data":[
      {
         "id":"701EB79D-F53A-2344-A86F-96F1E393A8B7",
         "id_link":"B55CA8E6-1609-654D-8432-4C3FD4156725",
         "author":"user",
         "title":"title",
"description":"description",

....

Use

ListBox1.AddRow(title, author, description)

for your listbox.

Thank you for your reply.

I get this:

Window1.Open, line 21
There is more than one method with this name but this does not match any of the available signatures.
ListBox1.AddRow(title, author, description)

Sorry, my bad. It needs to be

ListBox1.AddRow(n.value("title"), n.value("author"), n.value("description"))

author, title and description are arrays and can’t be used for AddRow.

Thank you very much for your help. It is now working fine.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.