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: 
crawfishmedia
Binge Watcher

ParseJSON() with returned data

Hi guys, I ran into an issue today with the returned response from the Tumblr API. Based on the answer to this post I might also post to the Tumblr API forum.
Basically what I am trying to do is create a Roku notification to the user if there is an issue with the API call, for any meta status other than 200. So the issue I need to describe is this: If I send a valid curl request in Mac Terminal to Tumblr to an inactive/unavailable domain, the JSON response comes back as:
{
"meta": {
"status": 404,
"msg": "Not Found"
},
"response": [

]
}
If I send the exact same curl URL using Roku, the ParseJSON function seems to break. I do have ParseJSON() running fine for a valid Tumblr account. I can pull data from the API no problem. For a valid account, I am able to access the meta status using:
json.meta.status
json.meta.msg
On Roku, I get a bright script error indicating the json object is invalid. To debug, if I print the data variable it comes up empty. If I print the json variable it comes up 'invalid'. This JSON response above looks correct but I am not 100% sure.
Code:
xfer=CreateObject("roURLTransfer")
xfer.seturl(url)
data=xfer.gettostring()
json = ParseJSON(data)

xfer &h0010 bsc:roUrlTransfer, refcnt=1
data &h8010 bsc:roString (2.1 was String), refcnt=1
json &h0080 Invalid val:invalid

Any tips are appreciated 🙂 Thanks
0 Kudos
2 REPLIES 2
TheEndless
Channel Surfer

Re: ParseJSON() with returned data

By default, no body is returned for url transfers that result in an error. You'll need to call "xfer.RetainBodyOnError(True)" if you need to parse the response instead of just checking the ResponseCode. It's also important to note that the RetainBodyOnError method is only available on 5.x firmwares, so you can't use it on legacy boxes running 3.1.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
crawfishmedia
Binge Watcher

Re: ParseJSON() with returned data

"TheEndless" wrote:
By default, no body is returned for url transfers that result in an error. You'll need to call "xfer.RetainBodyOnError(True)" if you need to parse the response instead of just checking the ResponseCode. It's also important to note that the RetainBodyOnError method is only available on 5.x firmwares, so you can't use it on legacy boxes running 3.1.

Thanks for the quick response. I added the code and it works now. Sucks that its only compatible with new firmware. So… now I have to add code to check the firmware version and adjust the feature set… sheesh
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.