Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
armagedon79
Visitor

ParseJSON: Data is empty

I tried it in new project it showed the following error.Any help will be much appreciated.
Thank you.
BRIGHTSCRIPT: ERROR: ParseJSON: Data is empty: pkg:/source/Utils.brs(18)


Utils.brs:
Sub playDefaultClip(app)        
sizeRect = app.canvas.GetCanvasRect()
app.player.SetDestinationRect(sizeRect) 'fullscreen

contentList = []
contentList.Push({
Stream: { url: "http://qthttp.apple.com.edgesuite.net/1010qwoeiuryfg/sl.m3u8" }
StreamFormat: "hls"
})
app.player.SetContentList(contentList)
app.player.play()
print "playing!"
End Sub

Function LoadNavigationContent(contentURL)
jsonAsString = ReadAsciiFile(contentURL)
[color=#FF0000]content = ParseJSON(jsonAsString)[/color]
return content
End Function


app controller:
' Factory method
Function initApp()

player = CreateObject("roVideoPlayer")
canvas = createObject("roImageCanvas")
port = CreateObject("roMessagePort")

canvas.SetMessagePort(port)
canvas.SetRequireAllImagesToDraw(false)

player.SetMessagePort(port)
player.SetLoop(false)
'player.SetPositionNotificationPeriod(5)

navigationContentURL = "pkg:/json/content.json"
navContent = LoadNavigationContent(navigationContentURL)

controls = {
menuControl:initMenuControl(navContent)
playerControl:initPlayerControl()
}

app = {

player:player
canvas:canvas
port:port

'navContent:navContent
controls:controls

paint:paintAll
handleEvents:loopEvents

onLeftKey:handleLeftKey
onUpKey:handleUpKey
onRightKey:handleRightKey
onDownKey:handleDownKey
onExitKey:handleExitKey
onOkKey:handleOkKey

}

return app

End Function

Function paintAll()
m.canvas.AllowUpdates(false)
m.canvas.Clear()

m.canvas.SetLayer(0, { Color: "#a6a663", CompositionMode: "Source" })
' Do, any painting here through the canvas object
for each k in m.controls
m.controls[k].paint(m.canvas)
end for

m.canvas.AllowUpdates(true)
m.canvas.Show()

End function

Function loopEvents()

while true
event = wait(0, m.port)
if (event<> invalid)
'print "events loop"
if (event.isRemoteKeyPressed())
index = event.GetIndex()
print index
if (index = 4) 'Left, pulls out the menu
m.onLeftKey()
else if (index = 2) 'Up
m.onUpKey()
else if (index = 5) 'Right,
m.onRightKey()
else if (index = 3) 'Down
m.onDownKey()
else if (index = 6) 'ok,
m.onOkKey()
else if (index = 0) 'Exit, exits app, if no control is visible
if(m.onExitKey() = 1)
ExitWhile
endif
endif
endif
endif
end while

End function

'If I had interfaces, this would become 'IUserInput'
Function handleLeftKey()
handled = false
for each k in m.controls
handled = m.controls[k].onLeftKey(m)
if(handled)
print 'handled!'
Exit For
end if
end for

end Function

Function handleUpKey()

for each k in m.controls
m.controls[k].onUpKey(m)
end for
end Function

Function handleRightKey()
for each k in m.controls
m.controls[k].onRightKey(m)
end for
end Function

Function handleDownKey()
for each k in m.controls
m.controls[k].onDownKey(m)
end for
end Function

Function handleExitKey()
for each k in m.controls
m.controls[k].onExitKey(m)
end for
return 1
end Function

Function handleOkKey()
for each k in m.controls
m.controls[k].onOkKey(m)
end for
end Function

' end of interface


Json playlist file example:

{"playlist":
[
{"title": "Channel One", "length": 0, "path": "http://www.playon.tv/online/iphone5/main.m3u8"},
{"title": "Channel Two", "length": 0, "path": "http://www.nasa.gov/multimedia/nasatv/NTV-Public-IPS.m3u8"},
{"title": "Channel Three", "length": 0, "path": "http://qthttp.apple.com.edgesuite.net/1010qwoeiuryfg/sl.m3u8"},
{"title": "Channel Four", "length": 0, "path": "http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8"},
{"title": "Channel Five", "length": 0, "path": "http://184.72.239.149/vod/smil:BigBuckBunny.smil/playlist.m3u8"}
]
}
0 Kudos
2 REPLIES 2
RokuKC
Roku Employee
Roku Employee

Re: ParseJSON: Data is empty

Well, presumably LoadNavigationContent is failing to read the file from ReadAsciiFile, so the string passed to ParseJSON is empty.

You might want to verify that "pkg:/json/content.json" is correct, as the most likely error is the file is not being found.

If you are using the Eclipse project, make sure that the json folder and content.json file is marked to be included in the zip file in the BrightScript Application Deployment.
0 Kudos
armagedon79
Visitor

Re: ParseJSON: Data is empty

Thanks
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.