chandu
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2015
02:06 AM
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:
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.
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.
3 REPLIES 3

RokuMarkn
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2015
07:32 AM
Re: Store a json object in variable
You need to retain the outermost curly brackets to make it an AssociativeArray.
--Mark
--Mark

TheEndless
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2015
08:25 AM
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)
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)


Roku Employee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2015
11:50 AM
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.