Skip to content
  • Home
  • Recent
  • Tags
  • 0 Unread 0
  • Categories
  • Unreplied
  • Popular
  • GitHub
  • Docu
  • Hilfe
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
ioBroker Logo

Community Forum

donate donate
  1. ioBroker Community Home
  2. Deutsch
  3. Skripten / Logik
  4. JSON Array in nodejs Objekt umwandeln

NEWS

  • Weihnachtsangebot 2025! 🎄
    BluefoxB
    Bluefox
    22
    1
    1.1k

  • UPDATE 31.10.: Amazon Alexa - ioBroker Skill läuft aus ?
    apollon77A
    apollon77
    48
    3
    9.1k

  • Monatsrückblick – September 2025
    BluefoxB
    Bluefox
    14
    1
    2.4k

JSON Array in nodejs Objekt umwandeln

Scheduled Pinned Locked Moved Skripten / Logik
4 Posts 3 Posters 830 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    XerXes777
    wrote on last edited by
    #1

    Moin Moin,

    wie kann ich aus diesem JSON,

    nodejs Datenpunkte erstellen?

    {"statusCode":200,"body":"[{\"error\":{\"type\":3,\"address\":\"/lights/30\",\"description\":\"resource, /lights/30, not available\"}}]","headers":{"server":"nginx","date":"Wed, 16 Jan 2019 22:33:24 GMT","content-type":"application/json","connection":"close","cache-control":"no-store, no-cache, must-revalidate, post-check=0, pre-check=0","pragma":"no-cache","expires":"Mon, 1 Aug 2011 09:00:00 GMT","access-control-max-age":"3600","access-control-allow-origin":"*","access-control-allow-credentials":"true","access-control-allow-methods":"POST, GET, OPTIONS, PUT, DELETE, HEAD","access-control-allow-headers":"Content-Type"},"request":{"uri":{"protocol":"http:","slashes":true,"auth":null,"host":"IP","port":80,"hostname":"IP","hash":null,"search":null,"query":null,"pathname":"/api/KEY/lights/30","path":"/api/KEY/lights/30","href":"http://IP/api/KEY/lights/30"},"method":"GET","headers":{}}}
    

    Ich brauche:

    type:

    address:

    description:

    Dies funktioniert:

    console.warn(response.statusCode)
    

    Wenn ich:

    console.warn(response.body)
    

    eingebe bekomme ich den kompletten array als string ausgegeben.

    Wenn ich:

    console.warn(response.body[0]['error'].type)
    

    oder

    console.warn(response.body[0].error.type)
    

    probiere bekomme ich einen TypeError.

    Kann mir da jemand helfen?

    Mit freundlichen Grüßen

    Kevin

    1 Reply Last reply
    0
    • apollon77A Online
      apollon77A Online
      apollon77
      wrote on last edited by
      #2

      In Body steht es als String.

      const body = JSON.parse(response.body);

      Dann kannst du drauf zugreifen.

      Gesendet vom Handy …

      Beitrag hat geholfen? Votet rechts unten im Beitrag :-) https://paypal.me/Apollon77 / https://github.com/sponsors/Apollon77

      • Debug-Log für Instanz einschalten? Admin -> Instanzen -> Expertenmodus -> Instanz aufklappen - Loglevel ändern
      • Logfiles auf Platte /opt/iobroker/log/… nutzen, Admin schneidet Zeilen ab
      1 Reply Last reply
      0
      • X Offline
        X Offline
        XerXes777
        wrote on last edited by
        #3

        Aber meine response ist ein JSON.

        Ich habe nur mit:

        console.log(JSON.stringify(response));
        

        lesbar im LOG gemacht und hier rein kopiert.

        1 Reply Last reply
        0
        • Lenny.CBL Offline
          Lenny.CBL Offline
          Lenny.CB
          Most Active
          wrote on last edited by
          #4

          @XerXes777:

          Aber meine response ist ein JSON.

          Ich habe nur mit:

          console.log(JSON.stringify(response));
          

          lesbar im LOG gemacht und hier rein kopiert. `

          Ich bin auch grad am Lernen, hatte vor Kurzem ein ähnliches Problem:

          ich vermute, deine Frunktion sieht so aus: function (error, response, body) {

          wenn dein body so ausschaut:

          {"error":{"type":3,"address":"/lights/30","description":"resource, /lights/30, not available"}}
          

          dann versuche mal:

          var obj = JSON.parse(body);
          
          log('Type: ' + obj[Object.keys(obj)[0]].type);
          log('Address: ' + obj[Object.keys(obj)[0]].address);
          log('Description: ' + obj[Object.keys(obj)[0]].description);
          
          1 Reply Last reply
          1
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          Support us

          ioBroker
          Community Adapters
          Donate

          892

          Online

          32.5k

          Users

          81.6k

          Topics

          1.3m

          Posts
          Community
          Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen | Einwilligungseinstellungen
          ioBroker Community 2014-2025
          logo
          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Home
          • Recent
          • Tags
          • Unread 0
          • Categories
          • Unreplied
          • Popular
          • GitHub
          • Docu
          • Hilfe