Forum Discussion

gouldtv's avatar
gouldtv
Visitor
15 years ago

Adding XML or JSON parsing to SimpleGrid.brs example

I'm trying to configure the SimpleGrid.brs sample and get it integrated with either XML or JSON feeds from my host. Can anyone share with me some sample code for pulling in either XML or JSON data that's compatible with SimpleGrid.brs? I see that there's code in the SimplePlayer/CategoryFeeds.brs file, but I'm having difficulty merging that logic with the SimpleGrid sample. If someone could show me the section of code that could follow this comment in the source, I'd appreciate it:

For this example, we just cheat and
'** create and return a static array with just the minimal items
'** set, but ideally, you'd go to a feed service, fetch and parse
'** this data dynamically, so content for each category is dynamic
'********************************************************************
Function getShowsForCategoryItem(category As Object) As Object



Any advice is greatly appreciated.

1 Reply

  • Handling XML in BrightScript is much easier than JSON, but either is possible. Take a look at the documentation for roXMLElement. Some very simple XML parsing logic might look like this:

    showList = []
    xml = CreateObject("roXMLElement")
    if xml.Parse(xmlString) ' where xmlString is a chunk of valid XML you've fetched from some cloud service
    for each item in xml.item
    showList.Push({
    title: item.title.GetText()
    sdPosterURL: item.image.GetText()
    hdPosterURL: item.image.GetText()
    ' etc...
    })
    next
    end if