Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

HTML5 Panel passing JSON data to javascript

Explorer ,
May 11, 2016 May 11, 2016

Hi Bruce,

I will soon be working on an HTML5 panel that will be receiving some JSON data through a URL call.

Is there a way to pass this JSON data to the javascript portion of the panel, so I can access all the objects?

thanks,

Kelly

TOPICS
SDK
1.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Employee , May 12, 2016 May 12, 2016

Thomas is right.


This may help, with passing JSON back from ExtendScript, to JavaScript:

HTML Panels Tips: #5 passing Objects from JSX to HTML | Photoshop, etc.

Also relevant:

ExtendScript ToolkitFrancois Tarlier's Blog | Francois Tarlier's blog

Translate
Participant ,
May 12, 2016 May 12, 2016

Kelly,

you can simply put all Javascript (that is required to call the JSON object) inside of the main index.html file. It works just like in a standard browser. Once you received the JSON obj, you can pass it around in your HTML or Javascript code as you like.

Thomas

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
May 12, 2016 May 12, 2016

Thomas is right.


This may help, with passing JSON back from ExtendScript, to JavaScript:

HTML Panels Tips: #5 passing Objects from JSX to HTML | Photoshop, etc.

Also relevant:

ExtendScript ToolkitFrancois Tarlier's Blog | Francois Tarlier's blog

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 12, 2016 May 12, 2016

Okay thanks.  I'll check these to links out.  However, I guess maybe I worded my question wrong in the first place.

Can you also pass the JSON object from the html file to ExtendScript?

thanks,

Kelly

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
May 12, 2016 May 12, 2016

I'm not sure; no one's ever asked me about handling JSON, within ExtendScript. Usually goes the other way.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 12, 2016 May 12, 2016

Yes you can pass data over to Extendscript. If your JSON is an object, you would have to stringify it first. Example:

var my_json = {foo:"bar"};

var csInterface = new CSInterface();

csInterface.evalScript("$.your_extendscript_function( " + JSON.stringify(my_json) + " )");

Thomas

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 12, 2016 May 12, 2016
LATEST

Thanks everyone for your input.

I went with Thomas' suggestion to stringify.

Unfortunately I had to do a few tricks to parse it back into an array of objects.  (A few splits and a few replaces)

But in the end I was able to get what I needed.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 12, 2016 May 12, 2016

Grab this file: GitHub - douglascrockford/JSON-js: JSON in JavaScript

In a .jsx file:

     #include "json2.js"

     var item = JSON.parse(info)

     var stringItem = JSON.stringify(jsonObject)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines