Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. json teilen

    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

    json teilen

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

      @wolfgangkt
      Das JSON, das Du gepostet hast, lässt sich parsen. Teil 2 beginnt mit "Küchenfenster geschlossen".

      W 1 Reply Last reply Reply Quote 0
      • W
        wolfgangkt @paul53 last edited by

        @paul53 in dem Datenpunkt steht eigentlich immer das gleiche.
        liegt es vielleicht an dem Datenpunkt selbst ?

        {
          "type": "state",
          "common": {
            "name": {
              "en": "List of all devices",
              "de": "Liste aller Geräte",
              "ru": "Список всех устройств",
              "pt": "Lista de todos os dispositivos",
              "nl": "List van alle apparaten",
              "fr": "Liste de tous les dispositifs",
              "it": "Elenco di tutti i dispositivi",
              "es": "Lista de todos los dispositivos",
              "pl": "Lista wszystkich urządzeń",
              "zh-cn": "所有装置清单"
            },
            "type": "array",
            "role": "json",
            "read": true,
            "write": false
          },
          "native": {},
          "from": "system.adapter.device-watcher.0",
          "user": "system.user.admin",
          "ts": 1676195799090,
          "_id": "device-watcher.0.zigbee.listAll",
          "acl": {
            "object": 1636,
            "state": 1636,
            "owner": "system.user.admin",
            "ownerGroup": "system.group.administrator"
          }
        }
        
        paul53 1 Reply Last reply Reply Quote 0
        • paul53
          paul53 @wolfgangkt last edited by

          @wolfgangkt
          Der Datenpunkt ist vom Typ "array", kann also nicht geparst werden. Ändere Zeile 6 in

              let arr = dp.state.val;
          
          W 1 Reply Last reply Reply Quote 0
          • W
            wolfgangkt @paul53 last edited by

            @paul53 jetzt funktioniert es. Vielen Dank für die Hilfe 👍 👍 👍

            1 Reply Last reply Reply Quote 0
            • W
              wolfgangkt last edited by

              @paul53 zu früh gefreut. In den 2. Datenpunkt werden nur 3 Datensätze geschrieben.

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

                @wolfgangkt sagte: In den 2. Datenpunkt werden nur 3 Datensätze geschrieben.

                Ändere Zeile 8:

                    for(let i = 30; i < arr.length; i++) {
                
                W 1 Reply Last reply Reply Quote 0
                • W
                  wolfgangkt @paul53 last edited by

                  @paul53 jetzt funktionierts. Besten Dank Dank nochmal.

                  haus-automatisierung 1 Reply Last reply Reply Quote 0
                  • haus-automatisierung
                    haus-automatisierung Developer Most Active @wolfgangkt last edited by

                    @wolfgangkt Hier noch eine etwas kürzere Alternative:

                    const idJson = '0_userdata.0.testjson'; // Original
                    const idJson1 = '0_userdata.0.json1'; // Teil 1
                    const idJson2 = '0_userdata.0.json2'; // Teil 2
                      
                    on({ id: idJson, change: 'ne' }, (obj) => {
                        const arr = JSON.parse(obj.state.val);
                    
                        setState(idJson1, JSON.stringify(arr.slice(0, 30)), true);
                        setState(idJson2, JSON.stringify(arr.slice(30)), true);
                     });
                    
                    W 1 Reply Last reply Reply Quote 0
                    • W
                      wolfgangkt @haus-automatisierung last edited by

                      @haus-automatisierung Danke, kann ich auch nochmal probieren. Das Script von @paul53 funktioniert einwandfrei. Die 2 Tabellen in der VIS laufen schon zu meiner Zufriedenheit.

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

                        @wolfgangkt sagte: kann ich auch nochmal probieren.

                        Dann lass das Parsen in Zeile 6 weg (Datenpunkt liefert bereits ein Array).

                        W 1 Reply Last reply Reply Quote 0
                        • W
                          wolfgangkt @paul53 last edited by

                          @paul53 eine Frage hätte ich noch. Wie kann ich aus Original json bestimme Werte herausfiltern z.B alle Wassermelder und in einen eigenen Datenpunkt schreiben.

                          haus-automatisierung 1 Reply Last reply Reply Quote 0
                          • haus-automatisierung
                            haus-automatisierung Developer Most Active @wolfgangkt last edited by

                            @wolfgangkt z.B. mit Filter-Funktionen

                            arr.filter(v => v.Device.startsWith('Wassermelder'));
                            

                            Also

                            setState(idJson1, JSON.stringify(arr.filter(v => v.Device.startsWith('Wassermelder'))), true);
                            
                            W 1 Reply Last reply Reply Quote 0
                            • W
                              wolfgangkt @haus-automatisierung last edited by

                              @haus-automatisierung Super 👍 Vielen Dank. Klappt einwandfrei.

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

                              Support us

                              ioBroker
                              Community Adapters
                              Donate

                              733
                              Online

                              31.8k
                              Users

                              80.0k
                              Topics

                              1.3m
                              Posts

                              6
                              37
                              1722
                              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