- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
how can i import data from a local json file?
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@youssefsherif, when you post code don't do a screenshot, do a copy and paste into a code block. The icon looks like </> when you expand the toolbar when you make a post. It will open a popup for you to paste your code into.
Just replace the text in the code with the proper object property from the parsed JSON.
Instead of:
m.tile.descriptionText = "This is a description"
You would have:
m.tile.descriptionText = json[2].description
json[2] is third entry of json and is an object with several parts: title, poster, and description. Just "json" is an even larger object (an roArray) with, in this case, 3 entries each of which is an object itself (an roAssociativeArray). Array indices start from 0, so in this example json[3] doesn't exist. There's only json[0], json[1], and json[2]. You need to understand these concepts or you're going to have a tough time with BrightScript.
Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.
I am not a Roku employee.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: impoting data from a json file
By "local" do you mean it's part of the channel pkg/zip file?
Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.
I am not a Roku employee.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: impoting data from a json file
yes exactly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: impoting data from a json file
json = ParseJson(ReadAsciiFile("pkg:/dir/file.json")
Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.
I am not a Roku employee.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: impoting data from a json file
perfect thank you, will give it a shot
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: impoting data from a json file
if i have a json file that contains data of multiple tiles and each tile consists of 2 labels and a poster and i have the data in the json file how can i exactly use them?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: impoting data from a json file
When you use ParseJason you'll get an object back (or invalid if the JSON isn't valid), so you'd do something like this:
json = ParseJson(ReadAsciifile("pkg:/dir/file.json"))
' check json:
if json <> invalid then
print json.Count();" entries"
for i = 0 to json.Count()-1
print i,"Title is ";json[i].title
end for
end if
Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.
I am not a Roku employee.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: impoting data from a json file
okay thank you will try it 👌👌
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: impoting data from a json file
one more question if i want to assign the title to the title in json ow can i do that?
i tried but it didnt work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: impoting data from a json file
You don't need to do that as you will only get row #3