Search code examples
jsonbrightscript

Parsing JSON with Brightscript


I'm trying to parse JSON, based on the example here: http://blog.roku.com/developer/2012/07/16/json-support-comes-to-roku/

jsonAsString = ReadAsciiFile("pkg:/json/sample1.json")
m.json = ParseJSON(jsonAsString)
ShowPosterScreen(m.json.Videos, true)

I get this message in the debugger console:

Current Function:
057: Function LoadJSONFile() as void
058:     jsonAsString = ReadAsciiFile("pkg:/json/sample1.json")
059:     m.json = ParseJSON(jsonAsString)
060:     ShowPosterScreen(m.json.Videos, true)
061: End Function
'Dot' Operator attempted with invalid BrightScript Component or interface reference. (runtime error &hec) in ...AALAE4Bk/pkg:/source/main.brs(60)
060:     ShowPosterScreen(m.json.Videos, true)
Backtrace:
Function loadjsonfile() As
   file/line: /tmp/plugin/D...AALAE4Bk/pkg:/source/main.brs(60)
Function handlebuttonpress(id As Integer) As
   file/line: /tmp/plugin/D...AALAE4Bk/pkg:/source/main.brs(51)
Function main() As
   file/line: /tmp/plugin/D...AALAE4Bk/pkg:/source/main.brs(26)
Local Variables:
global   &h0020 rotINTERFACE:ifGlobal
m        &h0010 bsc:roAssociativeArray, refcnt=4
jsonasstring &h8010 bsc:roString (2.1 was String), refcnt=1
BrightScript Debugger>

UPDATE: If I include a Makefile and zip the contents and load through development browser...it works. Not working when exporting through Eclipse.


Solution

  • That sounds like a bug in the Eclipse Brightscript plugin of some kind, most likely, in some way it is not loading the file containing your ShowPosterScreen function.

    Please check the Roku Developer forum, at the very top is the section for discussion of the Eclipse Plugin. Here is a direct link.