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

Re: impoting data from a json file

Jump to solution
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
      print i,"Poster is ";json[i].poster
      print i,"Description is ";json[i].description
   end for
end if
0 Kudos
youssefsherif
Streaming Star

Re: impoting data from a json file

Jump to solution

it gives me an error it doesnt compile

0 Kudos
youssefsherif
Streaming Star

Re: impoting data from a json file

Jump to solution
json = ParseJson(ReadAsciifile("pkg:/assets/Data.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
print i, "poster is " json[i].poster
print i, "desc is " json[i].description
end for
end if
 
this is what i did but this only displays the data on the terminal, i actually want to use the data to set them for the fields i already have and display on screen
0 Kudos
youssefsherif
Streaming Star

Re: impoting data from a json file

Jump to solution

Screenshot 2022-12-18 at 3.34.56 PM.pnginstead of doing m.tile.title = "title1"

and m.tile.descriptionText="this is new description for first tile"

i want to load it from the json file

0 Kudos
xoceunder
Roku Guru

Re: impoting data from a json file

Jump to solution

I don't understand why use a json with multiple content and get only 1, you should use a rowlist and select the one I want to display information from

0 Kudos
youssefsherif
Streaming Star

Re: impoting data from a json file

Jump to solution

i want to retrieve all data in the json file but i was just trying on one i dont know how to do that 

0 Kudos
xoceunder
Roku Guru

Re: impoting data from a json file

Jump to solution

Could you help to know more about the code so I can help you?

0 Kudos
youssefsherif
Streaming Star

Re: impoting data from a json file

Jump to solution

okay so what i want to do is that instead of setting the fields {title and image and description} manually from here like the code below i want to load them from the json file.

so instead of doing this:

m.tile.titleText = "Title1"
m.tile.descriptionText = "this is the new description for the first tile"
m.tile.posterUrl = "pkg:/assets/images/image1.jpg"
i want to use the data in the json file Screenshot 2022-12-18 at 4.51.05 PM.png

Screenshot 2022-12-18 at 3.34.56 PM.png

0 Kudos
renojim
Community Streaming Expert

Re: impoting data from a json file

Jump to solution

@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.

Roku Community Streaming Expert

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.
youssefsherif
Streaming Star

Re: impoting data from a json file

Jump to solution

worked perfectly thank you so much for your clarification and your help this helped me a lot. still trying to learn thank you so much again 🙏🙏

0 Kudos