Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. [gelöst] Javascript Objekte Zugriff

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    [gelöst] Javascript Objekte Zugriff

    This topic has been deleted. Only users with topic management privileges can see it.
    • ruhr70
      ruhr70 last edited by

      Der Durchlauf und die Verarbeitung hat 500ms gedauert.

      1 Reply Last reply Reply Quote 0
      • paul53
        paul53 last edited by

        @ruhr70:

            var obj = JSON.parse(json);
        
            for(var index in obj) { 
                // var indexObj = JSON.stringify(obj);
                if (/^fullcalendar/gi.test(index)) {
                    log(index); 
                    log(JSON.stringify(obj[index]));
                }
            }
        
        ```` `  
        

        Das Erzeugen des riesigen Objektes per JSON.parse(json) würde ich sparen (Speicherbedarf !) und die IDs folgendermassen ermitteln:

                var pos = 0;
                do {
                    pos = json.indexOf('fullcalendar.0.20', pos + 60);
                    var id = json.substr(pos, 35);
                    if(id.indexOf('pos') == -1 && id.length == 35) {
                        log(id); // Hier kann mit getObject(id) die Auswertung erfolgen
                    }    
                } while(pos != -1);
        
        

        Wenn man die ID hat, kommt man mit getObject(id) an alle Eigenschaften.

        1 Reply Last reply Reply Quote 0
        • S
          strackfi last edited by

          Dann kommt aber leider die Fehlermeldung

          TypeError: json.substr is not a function
          

          Edit:

          Habs jetzt hinbekommen anscheinend ist 'json' ein Objekt und kein String. (Stimmt das ?)

          Deshalb hab ichs jetzt mal so probiert (php Kentnisse sei Dank :D)

          json.toString().substr
          

          Und es geht

          1 Reply Last reply Reply Quote 0
          • paul53
            paul53 last edited by

            Bei mir funktioniert https://wiki.selfhtml.org/wiki/JavaScript/Objekte/String/substr.

            1 Reply Last reply Reply Quote 0
            • paul53
              paul53 last edited by

              @strackfi:

              anscheinend ist 'json' ein Objekt und kein String. (Stimmt das ?) `
              Nein, json ist ein String. Die Datei objects.json enthält einen JSON-String.

              Hast Du die Datei eingelesen ?

              const datei = "/opt/iobroker/iobroker-data/objects.json";
              
              
              1 Reply Last reply Reply Quote 0
              • S
                strackfi last edited by

                Ja wobei bei mir ein Rechteproblem auftritt 😞

                Welche Rechte muss ich den geben ?

                Selbst mit chmod 777 gehts nicht

                1 Reply Last reply Reply Quote 0
                • paul53
                  paul53 last edited by

                  @strackfi:

                  Ja wobei bei mir ein Rechteproblem auftritt `
                  Ich vermute das Problem eher dadurch, dass die Datei durch ioBroker geöffnet ist.

                  1 Reply Last reply Reply Quote 0
                  • S
                    strackfi last edited by

                    Die Fehlermeldung lautet aber:

                    Error: Permission denied
                             May not read /opt/iobroker/iobroker-data/objects.json
                    
                    1 Reply Last reply Reply Quote 0
                    • paul53
                      paul53 last edited by

                      @strackfi:

                      Die Fehlermeldung lautet aber: `
                      Vielleicht hat node.js fs ein Problem mit der Dateiendung .json ?

                      Unter Windows habe ich mal die Datei kopiert und dann die Kopie eingelesen, was funktioniert

                      exec('copy C://Program Files//ioBroker//iobroker-data//objects.json G://opt//iobroker//iobroker-data//objects.test');
                      
                      const datei = "G://opt//iobroker//iobroker-data//objects.test";
                      
                      

                      Und Du hast recht: Man muss .toString() anwenden

                              json = json.toString();
                              var pos = 0;
                              do {
                      
                      
                      1 Reply Last reply Reply Quote 0
                      • S
                        strackfi last edited by

                        Wenn ich die Datei kopiere und umbenenne in z.B nur "obj.json" im gleichen Verzeichnis, dann funktioniert das ganze 😄

                        Macht irgendwie keinen Sinn, wiee ich finde

                        Edit:

                        Diese Funktion gibt den Fehler aus:

                        
                            mods.fs.readFile = function () {
                                if (mods.path.normalize(arguments[0]).replace(/\\/g, '/').indexOf('-data/objects.json') !== -1) {
                                    if (adapter) {
                                        adapter.log.error('May not read ' + arguments[0]);
                                    } else {
                                        console.error('May not read ' + arguments[0]);
                                    }
                                    throw new Error('Permission denied');
                                }
                        
                                return mods.fs._readFile.apply(this, arguments);
                            };
                        
                        

                        Die if-Abfrage prüft ob der angegebene Pfad '-data/objects.json' enthält, dass ist anscheinend nicht gewollt ?

                        Gruß Finn

                        Edit2: habs gelöst. Ich kopiere einfach die Datei in eine obj.json und lese dann diese aus.

                        Vielen Dank für eure Hilfe 😄 😄

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post

                        Support us

                        ioBroker
                        Community Adapters
                        Donate

                        777
                        Online

                        31.7k
                        Users

                        79.9k
                        Topics

                        1.3m
                        Posts

                        4
                        26
                        3496
                        Loading More Posts
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes
                        Reply
                        • Reply as topic
                        Log in to reply
                        Community
                        Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
                        The ioBroker Community 2014-2023
                        logo