1

l am working on ionic 4 project. l am try to get data json array from url using native http for ionic . When l try to get data array from url json l got empty page ! .

data json l have is too long , l put here short json to show scheme

{
  "result": {
    "airprotname": {
      "code": "BGW"
    },
    "response": {
      "airport": {
        "plugin: {
          "schedule": {
            "arrival": {
              "data": [
                {
                  "flight": {
                    "identification": {
                      "id": iaw445,
                      "row": 4861006050
                    }
                  }
                }
              ]
            }
          }
        }
      }
    }
  }
}

my code

  export class HomePage {

      public items : any[] ; 
      constructor(private http: HTTP) {



        this.http.get('/airport.json?code=BGW', {}, {})
        .then(res=> {

          this.items = JSON.parse(res.data.result.response.airport.plugin.schedule.arrival.data)
        })
        .catch(error => {



        });

      }



    }

html

<ion-content>

   {{status}}
   <ion-list>
    <ion-item *ngFor="let item of items">
      {{item.flight.identification.id}}
      <div class="item-note" slot="end">
      </div>
    </ion-item>
  </ion-list>
</ion-content>

doc for native http

3
  • There is no .number.default properties in your JSON? Commented Feb 5, 2019 at 18:29
  • sorry , there was . but l have mistake when l copy the json . see my update Commented Feb 5, 2019 at 18:32
  • do you have any idea bro ? Commented Feb 5, 2019 at 18:46

1 Answer 1

1

parse the intial response you get, before trying to access your nested data, so do...

this.http.get('/airport.json?code=BGW', {}, {})
  .then(res=> {
     const parsed = JSON.parse(res.data);
     this.items = parsed.result.response.airport.plugin.schedule.arrival.data;
  })
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.