
scaper12123
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2016
08:46 AM
Json confusion
I am trying to get some info out of a json file online. I obtain and parse the file just fine but I can't for the life of me figure out what statement i need to make in order to get the info I need.
The problem stems from the format of the json file:
This is the entirety of the file in question. As a start, i've been trying to make a statement to check the boolean "Enable_Event_Streaming". The following is what I have in code:
Any help in sorting out this issue would be appreciated.
The problem stems from the format of the json file:
[{"Event_ID":15642,"Event_Title":"Saturday 6pm Service","Event_Start_Date":"2016-07-02T18:00:00","Event_End_Date":"2016-07-02T19:30:00","Enable_Event_Streaming":true,"Ministry_Name":"Weekend Worship","Congregation_ID":5,"Congregation_Name":"CCM Melbourne","Description":"Children's ministry is available for infants through 6th grade.","WebHTML":null}]
This is the entirety of the file in question. As a start, i've been trying to make a statement to check the boolean "Enable_Event_Streaming". The following is what I have in code:
sub CreateLiveMenu()
Stream = CreateObject("roAssociativeArray")
link_url = [the url link to the json file]
json_str = GetXML_1(link_url) 'retrieves the json file information (ignore the name). I am already assured this works so don't worry about it for now
json = ParseJson(json_str) 'I have already confirmed this statement works through a print statement displaying all the information in the file correctly
will_stream = json.Enable_Event_Streaming
if will_stream = true
print "will stream"
else
print "won't stream"
end if
return
end sub
Any help in sorting out this issue would be appreciated.
I AM THE ARCHMAGE... who is also rather new to Brightscript so forgive me for seeming inept at times.
4 REPLIES 4
belltown
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2016
09:01 AM
Re: Json confusion
In JSON, square brackets, [], denote a zero-based, comma-separated array of items. Even though your array only contains one item, you still need to index it:
json[0].Enable_Event_Streaming

scaper12123
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2016
09:29 AM
Re: Json confusion
"belltown" wrote:
In JSON, square brackets, [], denote a zero-based, comma-separated array of items. Even though your array only contains one item, you still need to index it:json[0].Enable_Event_Streaming
That explains a lot! thank you
I AM THE ARCHMAGE... who is also rather new to Brightscript so forgive me for seeming inept at times.
EnTerr
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2016
09:48 AM
Re: Json confusion
As a general tip on "how to fish" when having issue like that: put a STOP statement right after the problematic parse/ingest of xml/json. That throws you into console - and then via telnet there use ? (print) commands to figure out the exact access path:
BrightScript Debugger> ? jsonSee how i "fished" for the data, w/o process being mentally taxing?
<Component: roArray> =
[
<Component: roAssociativeArray>
]
BrightScript Debugger> ? json[0]
<Component: roAssociativeArray> =
{
congregation_id: 5
congregation_name: CCM Melbourne
description: Children's ministry is available for infants through 6th grade.
enable_event_streaming: true
event_end_date: 2016-07-02T19:30:00
event_id: 15642
event_start_date: 2016-07-02T18:00:00
event_title: Saturday 6pm Service
ministry_name: Weekend Worship
webhtml: invalid
}
BrightScript Debugger> ? json[0].enable_event_streaming
true

scaper12123
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2016
10:05 AM
Re: Json confusion
"EnTerr" wrote:
As a general tip on "how to fish" when having issue like that: put a STOP statement right after the problematic parse/ingest of xml/json. That throws you into console - and then via telnet there use ? (print) commands to figure out the exact access path:BrightScript Debugger> ? jsonSee how i "fished" for the data, w/o process being mentally taxing?
<Component: roArray> =
[
<Component: roAssociativeArray>
]
BrightScript Debugger> ? json[0]
<Component: roAssociativeArray> =
{
congregation_id: 5
congregation_name: CCM Melbourne
description: Children's ministry is available for infants through 6th grade.
enable_event_streaming: true
event_end_date: 2016-07-02T19:30:00
event_id: 15642
event_start_date: 2016-07-02T18:00:00
event_title: Saturday 6pm Service
ministry_name: Weekend Worship
webhtml: invalid
}
BrightScript Debugger> ? json[0].enable_event_streaming
true
Oh that is very helpful indeed! Many thanks, sir!
I AM THE ARCHMAGE... who is also rather new to Brightscript so forgive me for seeming inept at times.