Jquery Photoshop 2015扩展无法访问所有阵列项
我是一名新手程序员,不熟悉adobe extensions,但开发的扩展在Photoshop 2015中无法正常工作。它在2017年、2018年和2019年的PS中运行良好 我使用JSX从JSON文件读取数组数据,并使用main.js文件中的事件侦听器返回数据。扩展从返回的数组中读取设置。它可以完美地工作,除了在PS 2015中,它只能返回用户ID,而不能返回其他内容 从本地文件读取数据的JSX代码:Jquery Photoshop 2015扩展无法访问所有阵列项,jquery,json,jsx,photoshop,complex-event-processing,Jquery,Json,Jsx,Photoshop,Complex Event Processing,我是一名新手程序员,不熟悉adobe extensions,但开发的扩展在Photoshop 2015中无法正常工作。它在2017年、2018年和2019年的PS中运行良好 我使用JSX从JSON文件读取数组数据,并使用main.js文件中的事件侦听器返回数据。扩展从返回的数组中读取设置。它可以完美地工作,除了在PS 2015中,它只能返回用户ID,而不能返回其他内容 从本地文件读取数据的JSX代码: function ReadUserStoredDataFromFile(vfilepath){
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();
}
}
INDEX.HTML
var datareceived_arry = new Array();
MAIN.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
}
我使用了将被替换的虚拟测试数据。在PS 201720182019中,它返回的结果非常好。它使用CEP4,但我尝试过CEP6,问题仍然存在。感谢您的帮助。也许这背后有一个很好的故事,但显然CC2015中的事件对象解析器已经崩溃:当简单对象工作时(因此您的
datareceived\u arry['userinfo']['userid']
是可访问的),数组被转换为字符串:面板接收的JSON看起来像这样(注意所有数组现在都是字符串):
如果您确实想使用plugExternalObject
将数据从jsx传递到js,我相信您必须为您的对象编写一个自定义解析器。否则,我建议简单地将数据从jsx返回到js,并在回调中使用它:
JSX:
JS:
var datareceived\u arry=[];
var usermydocuments=csInterface.getSystemPath(SystemPath.MY\u DOCUMENTS);
设置超时(自动状态,1000);
函数AutoStatus()
{
var usdocfp=''“+usermydocuments+'/rt/autostatus.json'+'”;
csInterface.evalScript('ReadUserStoredDataFromFile('+usdocfp+'),函数(res)
{
datareceived\u arry=JSON.parse(res)//结果以字符串形式出现
//获取用户通知
var=“无”;
//添加用户ID
allunnotifications=“Userid:“+datareceived_arry['userinfo']['Userid']+”;
警报(datareceived_arry['userinfo']['userid']);//这显示了Fari的用户ID
警报(JSON.stringify(datareceived_arry['apps'][0]['version']);//这显示未定义
警报(JSON.stringify(datareceived_arry));//显示所有数据
$('#showdata').html(JSON.stringify(datareceived_arry));//这将显示所有数据
});
}
感谢a mill,它也适用于所有版本,您真是太棒了!
{"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":""}}
{
"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": ""
}
}
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;
}
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
});
}