Photoshop 2015 扩展名无法访问所有阵列项目



我是一名新手程序员,刚接触Adobe扩展,但开发了一个在Photoshop 2015中无法正常工作的扩展。它在PS 2017,2018和2019中完美运行。

我正在使用 JSX 从 JSON 文件中读取数组数据,并使用主文件中的事件侦听器返回数据.js。扩展从返回的数组中读取设置。它运行良好,除了在PS 2015中,它只能返回UserID,而不能返回其他任何内容。

从本地文件读取数据的 JSX 代码:

function ReadUserStoredDataFromFile(vfilepath){      
var rd = ReadFileData(vfilepath);     
SendDataToListenerJS("getuserstoredinfo",rd);    
}
function ReadFileData(vfullpath){    
fle = File(vfullpath); 
var filedata = 0;
if(fle.exists){    
fle.open('r');
filedata = fle.read();
fle.close();
}
return filedata;
}
function SendDataToListenerJS(JSlistenerName,DatatoJS){
try {
var xLib = new ExternalObject("lib:PlugPlugExternalObject");
} catch (e) {
alert(e);
}
if (xLib) {
var eventObj = new CSXSEvent(); 
eventObj.type = JSlistenerName;
eventObj.data = DatatoJS;
eventObj.dispatch();
}
}

索引

.HTML
var datareceived_arry = new Array();

主.JS代码

var usermydocuments = csInterface.getSystemPath(SystemPath.MY_DOCUMENTS);
setTimeout(AutoStatus, 1000);  
function AutoStatus(){
var usdocfp = '"' + usermydocuments + '/rt/autostatus.json' + '"';
csInterface.evalScript('ReadUserStoredDataFromFile('+ usdocfp +')');
}
csInterface.addEventListener("getuserstoredinfo", function(evt) {              
datareceived_arry = evt.data;              
var unoti = GetAllNotifications();                        
});
function GetAllNotifications(){          
//get user notification
var allunotifications = "none";
//add userid
allunotifications = "<b>Userid: " + datareceived_arry['userinfo']['userid'] + "</b>";
alert(datareceived_arry['userinfo']['userid']); //This shows the userid Fari
alert(JSON.stringify(datareceived_arry['apps'][0]['version'])); //This shows undefined
alert(JSON.stringify(datareceived_arry)); //This shows all the data
$('#showdata').html(JSON.stringify(datareceived_arry)); //This shows all the data
}

以下是保存到文件的数据:

{"0":0,"userinfo":{"userid":"fari","loginstatus":1,"usernotification":""},"apps":[{"appid":"rt5processor","accounttype":"Admin","status":"6","datestarted":"2019-10-11","usagedata":"1","flagcookiedata":"0","flagstorage":"0","appname":"RTPROCESSOR","version":"1.11.8","appnotification":"","apptype":"extension","updateflag":"0"},{"appid":"rt5sharpen","accounttype":"Admin","status":"6","datestarted":"2019-10-11","usagedata":"1","flagcookiedata":"0","flagstorage":"1","appname":"RTSHARPEN","version":"1.11.8","appnotification":"","apptype":"extension","updateflag":"0"}],"tutorials":[{"appid":"rtp","tutorialurl":"https://www.youtube.com/watch?v=W3cKq7S3qKc","featureonapp":"sharpen3"},{"appid":"rtp","tutorialurl":"https://www.youtube.com/watch?v=fKn5fG3M1m8","featureonapp":"Sharpen"},{"appid":"rtp","tutorialurl":"https://www.youtube.com/watch?v=m9M7J9uMrJk","featureonapp":"sharpen2"}],"misc":{"globalnotification":""}}

我使用了将被替换的虚拟测试数据。它在PS 2017,2018,2019中返回完全正常。它使用 cep 4,但我已经尝试了 cep 6,问题仍然存在。任何帮助表示赞赏。

也许这背后有一个很棒的故事,但显然 CC2015 中的事件对象解析器被破坏了: 虽然简单的对象工作(因此您的datareceived_arry['userinfo']['userid']是可访问的(,但数组被转换为字符串: 面板接收的JSON如下所示(请注意,现在所有数组都是字符串(:

{
"0": "0",
"tutorials": "[{"tutorialurl":"https://www.youtube.com/watch?v=W3cKq7S3qKc","appid":"rtp","featureonapp":"sharpen3"},{"tutorialurl":"https://www.youtube.com/watch?v=fKn5fG3M1m8","appid":"rtp","featureonapp":"Sharpen"},{"tutorialurl":"https://www.youtube.com/watch?v=m9M7J9uMrJk","appid":"rtp","featureonapp":"sharpen2"}]",
"userinfo":
{
"usernotification": "",
"userid": "fari",
"loginstatus": "1"
},
"apps": "[{"version":"1.11.8","datestarted":"2019-10-11","appname":"RTPROCESSOR","updateflag":"0","flagstorage":"0","accounttype":"Admin","appid":"rt5processor","status":"6","usagedata":"1","flagcookiedata":"0","apptype":"extension","appnotification":""},{"version":"1.11.8","datestarted":"2019-10-11","appname":"RTSHARPEN","updateflag":"0","flagstorage":"1","accounttype":"Admin","appid":"rt5sharpen","status":"6","usagedata":"1","flagcookiedata":"0","apptype":"extension","appnotification":""}]",
"misc":
{
"globalnotification": ""
}
}

如果你真的想使用PlugPlugExternalObject将数据从 JSX 传递到 JS,我相信你必须为你的对象编写一个自定义解析器。否则,我建议简单地将数据从jsx返回到js并在回调中使用它:

JSX:

function ReadUserStoredDataFromFile(vfilepath)
{
var rd = ReadFileData(vfilepath);
return rd;
}
function ReadFileData(vfullpath)
{
fle = File(vfullpath);
var filedata = 0;
if (fle.exists)
{
fle.open('r');
filedata = fle.read();
fle.close();
}
return filedata;
}

.JS:

var datareceived_arry = [];
var usermydocuments = csInterface.getSystemPath(SystemPath.MY_DOCUMENTS);
setTimeout(AutoStatus, 1000); 
function AutoStatus()
{
var usdocfp = '"' + usermydocuments + '/rt/autostatus.json' + '"';
csInterface.evalScript('ReadUserStoredDataFromFile(' + usdocfp + ')', function(res)
{
datareceived_arry = JSON.parse(res) // result comes as a string
//get user notification
var allunotifications = "none";
//add userid
allunotifications = "<b>Userid: " + datareceived_arry['userinfo']['userid'] + "</b>";
alert(datareceived_arry['userinfo']['userid']); //This shows the userid Fari
alert(JSON.stringify(datareceived_arry['apps'][0]['version'])); //This shows undefined
alert(JSON.stringify(datareceived_arry)); //This shows all the data
$('#showdata').html(JSON.stringify(datareceived_arry)); //This shows all the data
});
}

最新更新