0

I am new using Typescript, and I want to start working with JSON and be able to access its objects and attributes ... but it is getting very difficult to work on it, that is why I come to your knowledge of the code I want to be able to access the attribute of pavilions that are inside but I can not try using functions for of or functions for in and I can not achieve my mission (the attached next) ... my as I am started my skills in programming with this are not so good that we say .. many thanks for your help

for (let p in this.pabellon) {
  let i = p
  console.log(this.pabellon[p])
  for (let pab of this.pabellon) { 
      pab.pabellones[i]
  }
}

   "sectorCenter": {
     /// ......
    },
    "sectorPoly": [
     ///......
    ],
    "pabellones": [
      { // Pabellon 1
        "id": 1,
        "properties": [
        /// .......
        ],
        "coordsPoly": [
         ///.....
        ],
        "centerCoordsPab": {
         ///.....
        },
        "sitioCarga": [
        ///....
        ],
        "silos": [
          /// ....
        ]
      },

undefined or nothing

  • pavilions = pabellones attribute of JSON Code – Sergio M Jun 10 '19 at 15:57
  • 1
    JSON is a *textual notation* for data exchange. [(More here.)](http://stackoverflow.com/a/2904181/157247) If you're dealing with JavaScript or TypeScript source code, and not dealing with a *string*, you're not dealing with JSON. – T.J. Crowder Jun 10 '19 at 16:02
  • Welcome to Stack Overflow! Please take the [tour] (you get a badge!), have a look around, and read through the [help], in particular [*How do I ask a good question?*](/help/how-to-ask) I also recommend Jon Skeet's [Writing the Perfect Question](https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/). To be able to help you, we'd need to see the actual structure of what you're trying to loop through. The fragment above is just a fragment, so we don't know the structure, just that fragmentary part of it. Please update the question with a [mcve] (please do read that link). – T.J. Crowder Jun 10 '19 at 16:05

1 Answers1

0

Your question is hard to understand, but it sounds like you're looking for JSON.parse().

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse

frodo2975
  • 10,340
  • 3
  • 34
  • 41