Copy link to clipboard
Copied
Hi All,
New to JSON.
My request is no need to hard code in script (.jsx). For that am using JSON.
We need the "dropdownlist" list "Customer1", "Customer2", "Customer3" that should comes from JSON file.
Could you please help for this.
var w = new Window ("dialog");
var myDropdown = w.add ("dropdownlist", undefined, ["Customer1", "Customer2", "Customer3"]);
myDropdown.selection = 1;
w.show ();
Thanks in Advance
You can use eval to convert a JSON string into a JS object as follows
var a = eval('([ "Customer1", "Customer2", "Customer3" ])')
var b = eval('({"name":"John","age":30,"cars":[ "Ford", "BMW", "Fiat" ]})')
So in your code you could read a file with JSON string, convert it into JS object as shown above and then use the object to populate your UI like below
var myDropdown = w.add ("dropdownlist", undefined, a); Using eval can be a security threat so you could use a JSON library to parse out the strin
...Copy link to clipboard
Copied
You can use eval to convert a JSON string into a JS object as follows
var a = eval('([ "Customer1", "Customer2", "Customer3" ])')
var b = eval('({"name":"John","age":30,"cars":[ "Ford", "BMW", "Fiat" ]})')
So in your code you could read a file with JSON string, convert it into JS object as shown above and then use the object to populate your UI like below
var myDropdown = w.add ("dropdownlist", undefined, a); Using eval can be a security threat so you could use a JSON library to parse out the string for you as JSON. You could try something like
GitHub - douglascrockford/JSON-js: JSON in JavaScript
-Manan
Copy link to clipboard
Copied
Find more inspiration, events, and resources on the new Adobe Community
Explore Now