[FIXED] Photoshop 2015 Erweiterung nicht in der Lage, auf alle Array -Elemente zugreifen zu können

Ausgabe

Ich bin ein unerfahrener Programmierer und neu bei Adobe-Erweiterungen, habe aber eine Erweiterung entwickelt, die in Photoshop 2015 nicht richtig funktioniert. Sie funktioniert perfekt in PS 2017, 2018 und 2019.

Ich lese Array-Daten aus einer JSON-Datei mit JSX und verwende einen Ereignis-Listener in der Datei main.js, um die Daten zurückzugeben. Die Erweiterung liest die Einstellungen aus dem zurückgegebenen Array. Es funktioniert perfekt, außer in PS 2015, wo es nur die UserID zurückgeben kann, aber sonst nichts.

JSX-Code zum Lesen von Daten aus einer lokalen Datei:

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-Code

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
}

Hier sind die in einer Datei gespeicherten Daten:

{"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":""}}

Ich habe Dummy-Testdaten verwendet, die ersetzt werden. Es kehrt in PS 2017,2018,2019 einwandfrei zurück. Es verwendet cep 4, aber ich habe cep 6 ausprobiert und das Problem bleibt bestehen. Jede Hilfe geschätzt.

Lösung

Vielleicht gibt es eine großartige Geschichte dahinter, aber anscheinend ist der Event-Objekt-Parser in CC2015 kaputt: Während einfache Objektarbeit (damit Sie datareceived_arry['userinfo']['userid']zugänglich sind) werden Arrays in Strings konvertiert: JSON, das das Panel empfängt, sieht so aus (beachten Sie, dass alle Arrays jetzt Strings sind ):

{
    "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": ""
    }
}

Wenn Sie wirklich verwenden möchten, PlugPlugExternalObjectum Daten von JSX an JS zu übergeben, glaube ich, dass Sie einen benutzerdefinierten Parser für Ihr Objekt schreiben müssen. Andernfalls würde ich vorschlagen, einfach Daten von jsx an js zurückzugeben und in einem Rückruf zu verwenden:

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
        });
    }


Beantwortet von –
Sergey Kritskiy


Antwort geprüft von –
Timothy Miller (FixError Admin)

0 Shares:
Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like