PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, October 13, 2022

[FIXED] how retrieve value from json file

 October 13, 2022     axios, javascript, json     No comments   

Issue

axios.request(options).then(function (response) {
  console.log(response.data.destination);
}).catch(function (error) {
  console.error(error);
});

i am using axios library to retrieve data from an API which return below json object.

 "data": Object {
    "data": Object {
      "at_dstn": false,
      "at_src": true,
      "at_src_dstn": true,
      "awaiting_update": false,
      "destination": "INDB",
      "ir_train_name": "JODHPUR - INDORE Ranthambore SF Express",
      "is_run_day": true,
      "journey_time": 975,
      "new_message": "Train hasn't started yet. But all looks good.",
      "notification_date": "2022-08-21",
      "run_days": "MON,TUE,WED,THU,FRI,SAT,SUN",
      "seo_train_name": "Intercity Express",
      "source": "JU",
      "spent_time": 0.13,
      "std": "2022-08-21 05:00",
      "success": true,
      "title": "Train starts at 05:00",
      "train_name": "JODHPUR - INDORE Ranthambore SF Express",
      "train_number": "12466",
      "train_start_date": "2022-08-21",
      "upcoming_stations": Array [],
      "user_id": 0,
    },
    "message": "Success",
    "status": true,
    "timestamp": 1661021331914,
  },

in this json file, i want to retieve destination value which can be access by

response.data.destination

but it returns value as undefined. so is there somthing i am missing


Solution

Axios returns the response with data as shown in your response. If you want to get the destination values use this.

response.data.data.destination


Answered By - ghkatende
Answer Checked By - Terry (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing