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: 
EnTerr
Roku Guru

Re: Help Parse XML

"malort" wrote:
AA does not have a .count()

Oh <censor> me!
Apparently i live in the future, because on the box where i wrote and tested this
BrightScript Debugger> ? {}.count()
0
Let me think what i can do.
0 Kudos
EnTerr
Roku Guru

Re: Help Parse XML

"btpoole" wrote:
I kinda that it was all good since it got thru the attributes but it kicks on res.count < 1 line. It breaks to the console as you thought.
My apologies - turned out my code relied on a feature that is not in current firmware.
To fix it, replace res.count() < 1 on the erroring line with res.isEmpty(). I fixed my original post, you can copy&paste from that.
Try the example and see if any hiccups?

Thanks @malort for spotting the issue - you insisting with example that "AA does not have a .count()" made me realize the err in my ways. And while fixing it i saw second issue too - that present day formatJSON() does not work on arrays.

When I ?type(xml) I get nothing back.
Here you probably ran into that known bug of the firmware, where every other time on error it does not give you the console but instead completely exits the channel. Even so often (1 out of 2) it catches me off-guard. Try hitting Enter first just to see if console is responsive or not ("hanging").
0 Kudos
btpoole
Channel Surfer

Re: Help Parse XML

EnTerr
No need for apologies. As I was looking over the code, I was trying to figure out the <2 followed by <1 on next line. Thought maybe using = 0 instead of < 1, but isEmpty() is better. Thanks again. I will try this and see how it runs.
Thanks again
0 Kudos
btpoole
Channel Surfer

Re: Help Parse XML

Since there is not a .count(), is there anyway to count the number of shows (name) that may be present in a particular amount of time say 1 hour?

Also, on the dump function, I have pushed the day and time values to array:

day.push(day_sched[0].attr)
time.push(hour_sched[0].attr)

is there a way to push the show(called out as name in file) and network to an array? I have tried:
showname.push(hour_sched.name)
?showname
networkname.push(hour_sched.network)
?networkname

Kinda of odd, it gives me a Dot operator error on these lines yet it prints just as I thought it would:
the show name
the network
0 Kudos
EnTerr
Roku Guru

Re: Help Parse XML

"btpoole" wrote:
Since there is not a .count(), is there anyway to count the number of shows (name) that may be present in a particular amount of time say 1 hour

You might have been confused by our exchange above. There is no .count() for dictionaries ("roAssociativeArray", the ones in curly brackets, e.g. {key: "value"} ) but .count() for arrays (roArray, e.g. [1, "two"] ) is working fine, no worries.

Accordingly, looking at previous example
function dump(schedule):
for i = 1 to schedule.count()-1:
day_sched = schedule[i]
day = day_sched[0].attr
for j = 1 to day_sched.count()-1:
hour_sched = day_sched[j]
time = hour_sched[0].attr
for k = 1 to hour_sched.count()-1:
? day, time, hour_sched[k].name
end for
end for
end for
end function

- schedule.count()-1 will give you how many days are included in the schedule
- when looking at a specific day (i.e. inside for i loop), day_sched.count()-1 gives the number of time slots
- when focusing on a specific time slot in particular day (i.e. inside for j ), hour_sched.count()-1 gives the number of shows there

I don't understand the rest of your question/comment. Maybe try being more specific, copy&paste (small) piece of code that gives you trouble, also copy&paste the exact error, etc
0 Kudos