Parse and access JSON data

I have some new data from Microchip it is JSON format.

I needs to load, search for a specific items and get the link URL.

As in this example:


    "pic12f683": [
        {
            "date": 1632473350,
            "title": "PIC12F683 Data Sheet",
            "link": "https:\/\/ww1.microchip.com\/downloads\/en\/DeviceDoc\/41211D_.pdf"
        }
    ],

I got this far. But, even this may be incorrect.

url = "https://media.microchip.com/feeds/disti-datasheets.json"
data = secureSite.Get( url, 10)
Var datasheets As New JSONItem
datasheets.Load(data)

Advice to load, search and return the URL please.

It’s hard to say exactly since you only gave us a portion of the JSON, but using your example, something like this will work:

var j as new JSONItem( data )

var pic as JSONItem = j.Value( "pic12f683" )
for i as integer = 0 to pic.Count - 1
  var subItem as JSONItem = pic.ChildAt( i )
  if subItem.HasKey( "link" ) then
    // use subItem.Value( "link" )
  end if
next
1 Like

Thank you. Resolved using your approach.

I defined a string variable to from the UI/drop down.
Then, set URL to the subItem() and then opened the webpage.

I use variables to enable debugging, the code could be smaller but walking the debugger is so important.

Solution as follows:

Dim chip as String
chip = "pic"+PICInfoForm.ChipDropDown.SelectedRow.ToText.Lowercase

try 
  url = "https://media.microchip.com/feeds/disti-datasheets.json"
  data = secureSite.Get( url, 10)
  
  var j as new JSONItem( data )
  
  var pic as JSONItem = j.Value( chip )
  for i as integer = 0 to pic.Count - 1
    var subItem as JSONItem = pic.ChildAt( i )
    if subItem.HasKey( "link" ) then
      ' msgbox (subItem.Value( "link" ))
      url =  subItem.Value( "link" )
      showurl url
    end if
  next
  
Catch e As IOException 
  
end try

Most grateful.