Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. [Gelöst] Array 2 JSON

    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] Array 2 JSON

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

      Hallo Zusammen,

      Das Ergebnis von var statbody = JSON.parse(body); sieht wie folgt aus:

      {'status':'ok','time_server':1576323720,'time_exec':0,'body':[{'_id':'70:ee:50:1f:6b:f0','place':{'location':[7.035135874779104,50.82748439468796],'timezone':'Europe/Berlin','country':'DE','altitude':58,'city':'Rhein-Sieg-Kreis','street':'Schwanenweg'},'mark':14,'measures':{'02:00:00:1f:5c:68':{'res':{'1576323586':[7.2,81]},'type':['temperature','humidity']},'70:ee:50:1f:6b:f0':{'res':{'1576323622':[991.3]},'type':['pressure']},'05:00:00:05:64:2e':{'res':{'1576323612':[0]},'type':['rain']}}}]}
      

      Nun möchte ich aber nur die Werte "body" haben und und ändere den Befehl nach JSON.stringify(JSON.parse(body).body); und bekomme auch die gewünschten Werte.

      [{"_id":"70:ee:50:1f:6b:f0","place":{"location":[7.035135874779104,50.82748439468796],"timezone":"Europe/Berlin","country":"DE","altitude":58,"city":"Rhein-Sieg-Kreis","street":"Schwanenweg"},"mark":14,"measures":{"02:00:00:1f:5c:68":{"res":{"1576323586":[7.2,81]},"type":["temperature","humidity"]},"70:ee:50:1f:6b:f0":{"res":{"1576323622":[991.3]},"type":["pressure"]},"05:00:00:05:64:2e":{"res":{"1576323612":[0]},"type":["rain"]}}}]
      

      Egal was ich versuche, bekomme ich die 1. und letzte eckige Klammer nicht weg. Habe schon einiges zum Thema Array to JSON gefunden und auch ausoribiert, aber leider ohne Erfolg.

      Vielleicht hat hier jemand eine gute Idee um den JSON zu erhalten.

      {"_id":"70:ee:50:1f:6b:f0","place":{"location":[7.035135874779104,50.82748439468796],"timezone":"Europe/Berlin","country":"DE","altitude":58,"city":"Rhein-Sieg-Kreis","street":"Schwanenweg"},"mark":14,"measures":{"02:00:00:1f:5c:68":{"res":{"1576323586":[7.2,81]},"type":["temperature","humidity"]},"70:ee:50:1f:6b:f0":{"res":{"1576323622":[991.3]},"type":["pressure"]},"05:00:00:05:64:2e":{"res":{"1576323612":[0]},"type":["rain"]}}}
      

      Vielen Dank und Gruß
      RK

      paul53 2 Replies Last reply Reply Quote 0
      • paul53
        paul53 @RKBroker last edited by

        @RKBroker sagte in Array 2 JSON:

        bekomme ich die 1. und letzte eckige Klammer nicht weg.

        JSON ist ein String. Mit String-Funktionen sollte es kein Problem sein.

        json = json.substring(1, json.length - 1));
        
        R 1 Reply Last reply Reply Quote 0
        • R
          RKBroker @paul53 last edited by

          @paul53 Super!! Vielen Dank! Hat funktioniert.👍 👍

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

            @RKBroker sagte:

            JSON.stringify(JSON.parse(body).body);

            Es sollte auch so funktionieren:

            JSON.stringify(JSON.parse(body).body[0]);
            
            1 Reply Last reply Reply Quote 0
            • First post
              Last post

            Support us

            ioBroker
            Community Adapters
            Donate

            751
            Online

            31.8k
            Users

            80.0k
            Topics

            1.3m
            Posts

            javascript
            2
            4
            451
            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