Quantcast
Channel: Adobe Community : Popular Discussions - Illustrator Scripting
Viewing all articles
Browse latest Browse all 12845

Convert string (string of JSON) to JSON object?

$
0
0

**EDIT**

I finally figured out how to use #include instead of file.read();. This solves my immediate problem. However I am still curious as to whether it's possible to do what I'm asking for below, just in case there comes a situation where for whatever reason I cannot simply use #include. Thanks everyone. =)

**EDIT**

 

**EDIT 2**

Anyone know how to use #include for a file whose name is determined during script execution?

For example.. the variable orderNumber is generated by a prompt window (lets say the result is 1234567). the file i want to include will be named "1234567.js).

What I want to do is something like:

#include "~/Desktop/Info Folder/" + orderNumber + ".js"

(then I want to assign a variable to the result somehow, since it's simply an anonymous object at this point and i don't know how to access it's contents);

**EDIT 2**

 

Hey all. I have a (most likely really stupid) question about how to take a string that contains the JSON text and simply change it's type from "string" to "object"... I'm probably wording this very badly.

 

I'm fetching a .js file from my local network and setting a variable to the result of file.read();

 

The contents of the file is an anonymous object in JSON. However, when i use file.read(); the object is brought in as a string, like this:

 

'{"roster":[{"name":"Fink","number":"19","jerseySize":"XL","qty":"1","topId":"78531"},{thi s is the next player},{this is the next player}]}'

 

That is a massively simplified version of what i'm actually reading, but you get the point. I want to be able to bring that object into the script that I'm running and create new objects based on the pertinent information (in this case i only need the values for "name", "number", and "jerseySize").

 

So my question is this. how do i turn the above string of JSON into:

 

var roster = [

     {

     "name":"Fink",

     "number":"19",

     "jerseySize":"XL"},

     {

     next player

     },

     {

     next player

     }

]

 

???? A google search reveals the method JSON.parse(text). But that is not supported in ESTK.


Viewing all articles
Browse latest Browse all 12845

Trending Articles