如何解析json文件中另一个对象内的对象

时间:2018-10-11 07:00:06

标签: javascript json

如何解析json文件中另一个对象内的对象? 以下是json响应,我想解析火车名称,运行天数和运行时间

{
  "total": 14,
  "debit": 1,
  "response_code": 200,
  "trains": [{
    "name": "KUMBHA EXPRESS",
    "days": [{
      "runs": "Y",
      "code": "MON"
    }, {
      "runs": "Y",
      "code": "TUE"
    }, {
      "runs": "N",
      "code": "WED"
    }, {
      "runs": "Y",
      "code": "THU"
    }, {
      "runs": "Y",
      "code": "FRI"
    }, {
      "runs": "N",
      "code": "SAT"
    }, {
      "runs": "Y",
      "code": "SUN"
    }],
    "classes": [{
      "name": "SECOND AC",
      "code": "2A"
    }, {
      "name": "AC CHAIR CAR",
      "code": "CC"
    }, {
      "name": "FIRST CLASS",
      "code": "FC"
    }, {
      "name": "SLEEPER CLASS",
      "code": "SL"
    }, {
      "name": "SECOND SEATING",
      "code": "2S"
    }, {
      "name": "THIRD AC",
      "code": "3A"
    }, {
      "name": "FIRST AC",
      "code": "1A"
    }, {
      "name": "3rd AC ECONOMY",
      "code": "3E"
    }],
    "number": "12369",
    "to_station": {
      "name": "SULTANPUR",
      "code": "SLN",
      "lng": 82.0,
      "lat": 26.25
    },
    "from_station": {
      "name": "VARANASI JN",
      "code": "BSB",
      "lng": 83.0076292,
      "lat": 25.3356491
    },
    "travel_time": "02:03",
    "dest_arrival_time": "03:58",
    "src_departure_time": "01:55"
  }, {
    "name": "VARUNA EXPRESS",
    "days": [{
      "runs": "N",
      "code": "MON"
    }, {
      "runs": "Y",
      "code": "TUE"
    }, {
      "runs": "Y",
      "code": "WED"
    }, {
      "runs": "N",
      "code": "THU"
    }, {
      "runs": "Y",
      "code": "FRI"
    }, {
      "runs": "Y",
      "code": "SAT"
    }, {
      "runs": "Y",
      "code": "SUN"
    }],
    "classes": [{
      "name": "SECOND AC",
      "code": "2A"
    }, {
      "name": "AC CHAIR CAR",
      "code": "CC"
    }, {
      "name": "FIRST CLASS",
      "code": "FC"
    }, {
      "name": "SLEEPER CLASS",
      "code": "SL"
    }, {
      "name": "SECOND SEATING",
      "code": "2S"
    }, {
      "name": "THIRD AC",
      "code": "3A"
    }, {
      "name": "FIRST AC",
      "code": "1A"
    }, {
      "name": "3rd AC ECONOMY",
      "code": "3E"
    }],
    "number": "24227",
    "to_station": {
      "name": "SULTANPUR",
      "code": "SLN",
      "lng": 82.0,
      "lat": 26.25
    },
    "from_station": {
      "name": "VARANASI JN",
      "code": "BSB",
      "lng": 83.0076292,
      "lat": 25.3356491
    },
    "travel_time": "02:18",
    "dest_arrival_time": "07:03",
    "src_departure_time": "04:45"
  }, {
    "name": "PPTA UDZ HUMSAFAR EXP",
    "days": [{
      "runs": "N",
      "code": "MON"
    }, {
      "runs": "N",
      "code": "TUE"
    }, {
      "runs": "N",
      "code": "WED"
    }, {
      "runs": "N",
      "code": "THU"
    }, {
      "runs": "Y",
      "code": "FRI"
    }, {
      "runs": "N",
      "code": "SAT"
    }, {
      "runs": "N",
      "code": "SUN"
    }],
    "classes": [{
      "name": "SECOND AC",
      "code": "2A"
    }, {
      "name": "AC CHAIR CAR",
      "code": "CC"
    }, {
      "name": "FIRST CLASS",
      "code": "FC"
    }, {
      "name": "SLEEPER CLASS",
      "code": "SL"
    }, {
      "name": "SECOND SEATING",
      "code": "2S"
    }, {
      "name": "THIRD AC",
      "code": "3A"
    }, {
      "name": "FIRST AC",
      "code": "1A"
    }, {
      "name": "3rd AC ECONOMY",
      "code": "3E"
    }],
    "number": "19670",
    "to_station": {
      "name": "SULTANPUR",
      "code": "SLN",
      "lng": 82.0,
      "lat": 26.25
    },
    "from_station": {
      "name": "VARANASI JN",
      "code": "BSB",
      "lng": 83.0076292,
      "lat": 25.3356491
    },
    "travel_time": "02:50",
    "dest_arrival_time": "08:00",
    "src_departure_time": "05:10"
  }, {
    "name": "BSB-SLN PASS.",
    "days": [{
      "runs": "Y",
      "code": "MON"
    }, {
      "runs": "Y",
      "code": "TUE"
    }, {
      "runs": "Y",
      "code": "WED"
    }, {
      "runs": "Y",
      "code": "THU"
    }, {
      "runs": "Y",
      "code": "FRI"
    }, {
      "runs": "Y",
      "code": "SAT"
    }, {
      "runs": "Y",
      "code": "SUN"
    }],
    "classes": [{
      "name": "SECOND AC",
      "code": "2A"
    }, {
      "name": "AC CHAIR CAR",
      "code": "CC"
    }, {
      "name": "FIRST CLASS",
      "code": "FC"
    }, {
      "name": "SLEEPER CLASS",
      "code": "SL"
    }, {
      "name": "SECOND SEATING",
      "code": "2S"
    }, {
      "name": "THIRD AC",
      "code": "3A"
    }, {
      "name": "FIRST AC",
      "code": "1A"
    }, {
      "name": "3rd AC ECONOMY",
      "code": "3E"
    }],
    "number": "54263",
    "to_station": {
      "name": "SULTANPUR",
      "code": "SLN",
      "lng": 82.0,
      "lat": 26.25
    },
    "from_station": {
      "name": "VARANASI JN",
      "code": "BSB",
      "lng": 83.0076292,
      "lat": 25.3356491
    },
    "travel_time": "03:40",
    "dest_arrival_time": "10:40",
    "src_departure_time": "07:00"
  }, {
    "name": "AMRITSAR EXPRESS",
    "days": [{
      "runs": "Y",
      "code": "MON"
    }, {
      "runs": "Y",
      "code": "TUE"
    }, {
      "runs": "Y",
      "code": "WED"
    }, {
      "runs": "Y",
      "code": "THU"
    }, {
      "runs": "Y",
      "code": "FRI"
    }, {
      "runs": "Y",
      "code": "SAT"
    }, {
      "runs": "Y",
      "code": "SUN"
    }],
    "classes": [{
      "name": "SECOND AC",
      "code": "2A"
    }, {
      "name": "AC CHAIR CAR",
      "code": "CC"
    }, {
      "name": "FIRST CLASS",
      "code": "FC"
    }, {
      "name": "SLEEPER CLASS",
      "code": "SL"
    }, {
      "name": "SECOND SEATING",
      "code": "2S"
    }, {
      "name": "THIRD AC",
      "code": "3A"
    }, {
      "name": "FIRST AC",
      "code": "1A"
    }, {
      "name": "3rd AC ECONOMY",
      "code": "3E"
    }],
    "number": "13049",
    "to_station": {
      "name": "SULTANPUR",
      "code": "SLN",
      "lng": 82.0,
      "lat": 26.25
    },
    "from_station": {
      "name": "VARANASI JN",
      "code": "BSB",
      "lng": 83.0076292,
      "lat": 25.3356491
    },
    "travel_time": "03:15",
    "dest_arrival_time": "11:55",
    "src_departure_time": "08:40"
  }, {
    "name": "FARAKKA EXPRESS",
    "days": [{
      "runs": "N",
      "code": "MON"
    }, {
      "runs": "Y",
      "code": "TUE"
    }, {
      "runs": "N",
      "code": "WED"
    }, {
      "runs": "N",
      "code": "THU"
    }, {
      "runs": "Y",
      "code": "FRI"
    }, {
      "runs": "N",
      "code": "SAT"
    }, {
      "runs": "Y",
      "code": "SUN"
    }],
    "classes": [{
      "name": "SECOND AC",
      "code": "2A"
    }, {
      "name": "AC CHAIR CAR",
      "code": "CC"
    }, {
      "name": "FIRST CLASS",
      "code": "FC"
    }, {
      "name": "SLEEPER CLASS",
      "code": "SL"
    }, {
      "name": "SECOND SEATING",
      "code": "2S"
    }, {
      "name": "THIRD AC",
      "code": "3A"
    }, {
      "name": "FIRST AC",
      "code": "1A"
    }, {
      "name": "3rd AC ECONOMY",
      "code": "3E"
    }],
    "number": "13413",
    "to_station": {
      "name": "SULTANPUR",
      "code": "SLN",
      "lng": 82.0,
      "lat": 26.25
    },
    "from_station": {
      "name": "VARANASI JN",
      "code": "BSB",
      "lng": 83.0076292,
      "lat": 25.3356491
    },
    "travel_time": "02:55",
    "dest_arrival_time": "14:05",
    "src_departure_time": "11:10"
  }, {
    "name": "BSB-JAT EXP.",
    "days": [{
      "runs": "Y",
      "code": "MON"
    }, {
      "runs": "Y",
      "code": "TUE"
    }, {
      "runs": "Y",
      "code": "WED"
    }, {
      "runs": "Y",
      "code": "THU"
    }, {
      "runs": "Y",
      "code": "FRI"
    }, {
      "runs": "Y",
      "code": "SAT"
    }, {
      "runs": "Y",
      "code": "SUN"
    }],
    "classes": [{
      "name": "SECOND AC",
      "code": "2A"
    }, {
      "name": "AC CHAIR CAR",
      "code": "CC"
    }, {
      "name": "FIRST CLASS",
      "code": "FC"
    }, {
      "name": "SLEEPER CLASS",
      "code": "SL"
    }, {
      "name": "SECOND SEATING",
      "code": "2S"
    }, {
      "name": "THIRD AC",
      "code": "3A"
    }, {
      "name": "FIRST AC",
      "code": "1A"
    }, {
      "name": "3rd AC ECONOMY",
      "code": "3E"
    }],
    "number": "12237",
    "to_station": {
      "name": "SULTANPUR",
      "code": "SLN",
      "lng": 82.0,
      "lat": 26.25
    },
    "from_station": {
      "name": "VARANASI JN",
      "code": "BSB",
      "lng": 83.0076292,
      "lat": 25.3356491
    },
    "travel_time": "02:10",
    "dest_arrival_time": "14:50",
    "src_departure_time": "12:40"
  }, {
    "name": "SHRAMJEEVI EXPRESS",
    "days": [{
      "runs": "Y",
      "code": "MON"
    }, {
      "runs": "Y",
      "code": "TUE"
    }, {
      "runs": "Y",
      "code": "WED"
    }, {
      "runs": "Y",
      "code": "THU"
    }, {
      "runs": "Y",
      "code": "FRI"
    }, {
      "runs": "Y",
      "code": "SAT"
    }, {
      "runs": "Y",
      "code": "SUN"
    }],
    "classes": [{
      "name": "SECOND AC",
      "code": "2A"
    }, {
      "name": "AC CHAIR CAR",
      "code": "CC"
    }, {
      "name": "FIRST CLASS",
      "code": "FC"
    }, {
      "name": "SLEEPER CLASS",
      "code": "SL"
    }, {
      "name": "SECOND SEATING",
      "code": "2S"
    }, {
      "name": "THIRD AC",
      "code": "3A"
    }, {
      "name": "FIRST AC",
      "code": "1A"
    }, {
      "name": "3rd AC ECONOMY",
      "code": "3E"
    }],
    "number": "12391",
    "to_station": {
      "name": "SULTANPUR",
      "code": "SLN",
      "lng": 82.0,
      "lat": 26.25
    },
    "from_station": {
      "name": "VARANASI JN",
      "code": "BSB",
      "lng": 83.0076292,
      "lat": 25.3356491
    },
    "travel_time": "01:58",
    "dest_arrival_time": "17:10",
    "src_departure_time": "15:12"
  }, {
    "name": "INDORE EXPRESS",
    "days": [{
      "runs": "N",
      "code": "MON"
    }, {
      "runs": "N",
      "code": "TUE"
    }, {
      "runs": "N",
      "code": "WED"
    }, {
      "runs": "N",
      "code": "THU"
    }, {
      "runs": "Y",
      "code": "FRI"
    }, {
      "runs": "N",
      "code": "SAT"
    }, {
      "runs": "N",
      "code": "SUN"
    }],
    "classes": [{
      "name": "SECOND AC",
      "code": "2A"
    }, {
      "name": "AC CHAIR CAR",
      "code": "CC"
    }, {
      "name": "FIRST CLASS",
      "code": "FC"
    }, {
      "name": "SLEEPER CLASS",
      "code": "SL"
    }, {
      "name": "SECOND SEATING",
      "code": "2S"
    }, {
      "name": "THIRD AC",
      "code": "3A"
    }, {
      "name": "FIRST AC",
      "code": "1A"
    }, {
      "name": "3rd AC ECONOMY",
      "code": "3E"
    }],
    "number": "19314",
    "to_station": {
      "name": "SULTANPUR",
      "code": "SLN",
      "lng": 82.0,
      "lat": 26.25
    },
    "from_station": {
      "name": "VARANASI JN",
      "code": "BSB",
      "lng": 83.0076292,
      "lat": 25.3356491
    },
    "travel_time": "02:15",
    "dest_arrival_time": "18:15",
    "src_departure_time": "16:00"
  }, {
    "name": "BSB-SLN PASS",
    "days": [{
      "runs": "Y",
      "code": "MON"
    }, {
      "runs": "Y",
      "code": "TUE"
    }, {
      "runs": "Y",
      "code": "WED"
    }, {
      "runs": "Y",
      "code": "THU"
    }, {
      "runs": "Y",
      "code": "FRI"
    }, {
      "runs": "Y",
      "code": "SAT"
    }, {
      "runs": "Y",
      "code": "SUN"
    }],
    "classes": [{
      "name": "SECOND AC",
      "code": "2A"
    }, {
      "name": "AC CHAIR CAR",
      "code": "CC"
    }, {
      "name": "FIRST CLASS",
      "code": "FC"
    }, {
      "name": "SLEEPER CLASS",
      "code": "SL"
    }, {
      "name": "SECOND SEATING",
      "code": "2S"
    }, {
      "name": "THIRD AC",
      "code": "3A"
    }, {
      "name": "FIRST AC",
      "code": "1A"
    }, {
      "name": "3rd AC ECONOMY",
      "code": "3E"
    }],
    "number": "54265",
    "to_station": {
      "name": "SULTANPUR",
      "code": "SLN",
      "lng": 82.0,
      "lat": 26.25
    },
    "from_station": {
      "name": "VARANASI JN",
      "code": "BSB",
      "lng": 83.0076292,
      "lat": 25.3356491
    },
    "travel_time": "03:55",
    "dest_arrival_time": "20:10",
    "src_departure_time": "16:15"
  }, {
    "name": "PNBE-KOTA EXPRESS",
    "days": [{
      "runs": "Y",
      "code": "MON"
    }, {
      "runs": "N",
      "code": "TUE"
    }, {
      "runs": "Y",
      "code": "WED"
    }, {
      "runs": "Y",
      "code": "THU"
    }, {
      "runs": "Y",
      "code": "FRI"
    }, {
      "runs": "N",
      "code": "SAT"
    }, {
      "runs": "N",
      "code": "SUN"
    }],
    "classes": [{
      "name": "SECOND AC",
      "code": "2A"
    }, {
      "name": "AC CHAIR CAR",
      "code": "CC"
    }, {
      "name": "FIRST CLASS",
      "code": "FC"
    }, {
      "name": "SLEEPER CLASS",
      "code": "SL"
    }, {
      "name": "SECOND SEATING",
      "code": "2S"
    }, {
      "name": "THIRD AC",
      "code": "3A"
    }, {
      "name": "FIRST AC",
      "code": "1A"
    }, {
      "name": "3rd AC ECONOMY",
      "code": "3E"
    }],
    "number": "13239",
    "to_station": {
      "name": "SULTANPUR",
      "code": "SLN",
      "lng": 82.0,
      "lat": 26.25
    },
    "from_station": {
      "name": "VARANASI JN",
      "code": "BSB",
      "lng": 83.0076292,
      "lat": 25.3356491
    },
    "travel_time": "02:20",
    "dest_arrival_time": "18:55",
    "src_departure_time": "16:35"
  }, {
    "name": "MARUDHAR EXPRES",
    "days": [{
      "runs": "N",
      "code": "MON"
    }, {
      "runs": "Y",
      "code": "TUE"
    }, {
      "runs": "N",
      "code": "WED"
    }, {
      "runs": "N",
      "code": "THU"
    }, {
      "runs": "Y",
      "code": "FRI"
    }, {
      "runs": "N",
      "code": "SAT"
    }, {
      "runs": "Y",
      "code": "SUN"
    }],
    "classes": [{
      "name": "SECOND AC",
      "code": "2A"
    }, {
      "name": "AC CHAIR CAR",
      "code": "CC"
    }, {
      "name": "FIRST CLASS",
      "code": "FC"
    }, {
      "name": "SLEEPER CLASS",
      "code": "SL"
    }, {
      "name": "SECOND SEATING",
      "code": "2S"
    }, {
      "name": "THIRD AC",
      "code": "3A"
    }, {
      "name": "FIRST AC",
      "code": "1A"
    }, {
      "name": "3rd AC ECONOMY",
      "code": "3E"
    }],
    "number": "14863",
    "to_station": {
      "name": "SULTANPUR",
      "code": "SLN",
      "lng": 82.0,
      "lat": 26.25
    },
    "from_station": {
      "name": "VARANASI JN",
      "code": "BSB",
      "lng": 83.0076292,
      "lat": 25.3356491
    },
    "travel_time": "02:15",
    "dest_arrival_time": "20:30",
    "src_departure_time": "18:15"
  }, {
    "name": "SDAH DLI  EXP",
    "days": [{
      "runs": "Y",
      "code": "MON"
    }, {
      "runs": "N",
      "code": "TUE"
    }, {
      "runs": "N",
      "code": "WED"
    }, {
      "runs": "N",
      "code": "THU"
    }, {
      "runs": "Y",
      "code": "FRI"
    }, {
      "runs": "N",
      "code": "SAT"
    }, {
      "runs": "N",
      "code": "SUN"
    }],
    "classes": [{
      "name": "SECOND AC",
      "code": "2A"
    }, {
      "name": "AC CHAIR CAR",
      "code": "CC"
    }, {
      "name": "FIRST CLASS",
      "code": "FC"
    }, {
      "name": "SLEEPER CLASS",
      "code": "SL"
    }, {
      "name": "SECOND SEATING",
      "code": "2S"
    }, {
      "name": "THIRD AC",
      "code": "3A"
    }, {
      "name": "FIRST AC",
      "code": "1A"
    }, {
      "name": "3rd AC ECONOMY",
      "code": "3E"
    }],
    "number": "13119",
    "to_station": {
      "name": "SULTANPUR",
      "code": "SLN",
      "lng": 82.0,
      "lat": 26.25
    },
    "from_station": {
      "name": "VARANASI JN",
      "code": "BSB",
      "lng": 83.0076292,
      "lat": 25.3356491
    },
    "travel_time": "02:13",
    "dest_arrival_time": "00:08",
    "src_departure_time": "21:55"
  }, {
    "name": "EKATMATA EXRESS",
    "days": [{
      "runs": "N",
      "code": "MON"
    }, {
      "runs": "N",
      "code": "TUE"
    }, {
      "runs": "Y",
      "code": "WED"
    }, {
      "runs": "N",
      "code": "THU"
    }, {
      "runs": "Y",
      "code": "FRI"
    }, {
      "runs": "N",
      "code": "SAT"
    }, {
      "runs": "N",
      "code": "SUN"
    }],
    "classes": [{
      "name": "SECOND AC",
      "code": "2A"
    }, {
      "name": "AC CHAIR CAR",
      "code": "CC"
    }, {
      "name": "FIRST CLASS",
      "code": "FC"
    }, {
      "name": "SLEEPER CLASS",
      "code": "SL"
    }, {
      "name": "SECOND SEATING",
      "code": "2S"
    }, {
      "name": "THIRD AC",
      "code": "3A"
    }, {
      "name": "FIRST AC",
      "code": "1A"
    }, {
      "name": "3rd AC ECONOMY",
      "code": "3E"
    }],
    "number": "14261",
    "to_station": {
      "name": "SULTANPUR",
      "code": "SLN",
      "lng": 82.0,
      "lat": 26.25
    },
    "from_station": {
      "name": "VARANASI JN",
      "code": "BSB",
      "lng": 83.0076292,
      "lat": 25.3356491
    },
    "travel_time": "02:10",
    "dest_arrival_time": "01:55",
    "src_departure_time": "23:45"
  }]
}

0 个答案:

没有答案