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: 
chandu
Visitor

Store a json object in variable

If anybody have any idea please share..How to Store a json object in variable?
actually i have a json object like:
{
"employees":[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter", "lastName":"Jones"}
]
}

i want to store it in a variable. like:
employeedetails = "employees":[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter", "lastName":"Jones"}
]
if i store it direct(in employeedetails) like above example it give me syntax error.
0 Kudos
3 REPLIES 3
RokuMarkn
Visitor

Re: Store a json object in variable

You need to retain the outermost curly brackets to make it an AssociativeArray.

--Mark
0 Kudos
TheEndless
Channel Surfer

Re: Store a json object in variable

In the 6.x firmware, you can't have quoted key names, so you'd likely need to use ParseJSON to convert the JSON string to an AssociativeArray.
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
RokuKC
Roku Employee
Roku Employee

Re: Store a json object in variable

"chandu" wrote:
If anybody have any idea please share..How to Store a json object in variable?


If the use case is that you are getting a JSON string from somewhere (like a web service) that you want to work with,
then the answer is to use the ParseJSON function to convert it to a BrightScript object representation.

ParseJSON will also handle things like embedded quotation marks and escape sequences in string values, null values, etc., and it will automatically handle the keys as case-sensitive / case-preserving.
0 Kudos