Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
chandu
Level 7

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
RokuMarkn
Level 7

Re: Store a json object in variable

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

--Mark
0 Kudos
TheEndless
Level 7

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