有没有一种方法可以从多个键下获取JSON值并将其存储为PHP值?

时间:2020-03-30 10:39:36

标签: javascript php json

我是编码领域的新手,正在尝试从给定的JSON文件中检索特定值,并将其存储为PHP变量,然后将其添加到SQL数据库中。

我已经阅读了大约六本教程,而且它们似乎只深入了一层,并从中获得了价值。

我正在尝试获取php中的粗体值。

功能{“属性”:{“ Master_Incident_Number”:“ QF2-19-097369 ”,“ IncidentType”:“ 植被大火”...。

Full JSON file here

是否有可能,如果有人可以,请帮助我指出这一点。

谢谢

1 个答案:

答案 0 :(得分:0)

使用map遍历features.attributes以访问键Master_Incident_NumberIncidentType

const input = {
  "features": [{
      "attributes": {
        "Master_Incident_Number": "QF4-20-011913",
        "IncidentType": "Vegetation Fire",
        "ResponseDate": 1580279411000,
        "LastUpdate": 1580357356000,
        "Location": "457 Ten Chain Rd, Kinleymore",
        "Region": "4 North Coast Region",
        "Latitude": -26.208141,
        "Longitude": 151.672965,
        "CurrentStatus": "Going",
        "VehiclesOnRoute": 1,
        "VehiclesOnScene": 0,
        "CurrentWarning": "Information",
        "MediaMessage": "There is a vegetation fire at this location. Smoke may affect residents and motorists in the area. Residents should close their doors and windows and keep medication close by if suffering from a respiratory condition. Motorists should use caution and drive to conditions. If you believe your property is under threat, you should call Triple Zero (000) immediately.",
        "FMETimestamp": "20200130142217.4726048",
        "OBJECTID": 1,
        "GlobalID": "5c6e0a07-aa7d-4e80-a44e-b652d2f0f18b",
        "Link": "https://"
      },
      "geometry": {
        "x": 151.672965,
        "y": -26.208141
      }
    },
    {
      "attributes": {
        "Master_Incident_Number": "QF4-20-012241",
        "IncidentType": "Permitted Burn (Attendance)",
        "ResponseDate": 1580353993000,
        "LastUpdate": 1580356129000,
        "Location": "22 Almond Rd, Benarkin North",
        "Region": "4 North Coast Region",
        "Latitude": -26.832734,
        "Longitude": 152.156489,
        "CurrentStatus": "Going",
        "VehiclesOnRoute": 0,
        "VehiclesOnScene": 4,
        "CurrentWarning": "Information",
        "MediaMessage": "There is a vegetation fire at this location. Smoke may affect residents and motorists in the area. Residents should close their doors and windows and keep medication close by if suffering from a respiratory condition. Motorists should use caution and drive to conditions. If you believe your property is under threat, you should call Triple Zero (000) immediately.",
        "FMETimestamp": "20200130142217.4798706",
        "OBJECTID": 2,
        "GlobalID": "2726c898-a6f4-4906-804f-d3f2e6c8a087",
        "Link": "https://"
      },
      "geometry": {
        "x": 152.156489,
        "y": -26.832734
      }
    },
    {
      "attributes": {
        "Master_Incident_Number": "QF6-20-012251",
        "IncidentType": "Vegetation Fire",
        "ResponseDate": 1580354969000,
        "LastUpdate": 1580358095000,
        "Location": "386 Main Western Rd, Tamborine Mountain",
        "Region": "6 South Eastern Region",
        "Latitude": -27.955333,
        "Longitude": 153.182491,
        "CurrentStatus": "Going",
        "VehiclesOnRoute": 2,
        "VehiclesOnScene": 1,
        "CurrentWarning": "Information",
        "MediaMessage": "There is a vegetation fire at this location. Smoke may affect residents and motorists in the area. Residents should close their doors and windows and keep medication close by if suffering from a respiratory condition. Motorists should use caution and drive to conditions. If you believe your property is under threat, you should call Triple Zero (000) immediately.",
        "FMETimestamp": "20200130142217.4813494",
        "OBJECTID": 3,
        "GlobalID": "e310dc73-695c-4466-8dc4-e6eb5344b406",
        "Link": "https://"
      },
      "geometry": {
        "x": 153.182491,
        "y": -27.955333
      }
    },
    {
      "attributes": {
        "Master_Incident_Number": "QF4-20-012274",
        "IncidentType": "Vegetation Fire",
        "ResponseDate": 1580357366000,
        "LastUpdate": 1580357666000,
        "Location": "2-21 Steindl St, Bundaberg East",
        "Region": "4 North Coast Region",
        "Latitude": -24.865996,
        "Longitude": 152.37337,
        "CurrentStatus": "Going",
        "VehiclesOnRoute": 1,
        "VehiclesOnScene": 0,
        "CurrentWarning": "Information",
        "MediaMessage": "There is a vegetation fire at this location. Smoke may affect residents and motorists in the area. Residents should close their doors and windows and keep medication close by if suffering from a respiratory condition. Motorists should use caution and drive to conditions. If you believe your property is under threat, you should call Triple Zero (000) immediately.",
        "FMETimestamp": "20200130142217.4828626",
        "OBJECTID": 4,
        "GlobalID": "a37695bd-ef88-49bd-813a-ca3133d42d83",
        "Link": "https://"
      },
      "geometry": {
        "x": 152.37337,
        "y": -24.865996
      }
    }
  ]
};

const output = input.features.map(({
  attributes: {
    Master_Incident_Number,
    IncidentType
  }
}) => console.log(Master_Incident_Number, IncidentType));

-编辑-

const input = {
  "features": [{
      "attributes": {
        "Master_Incident_Number": "QF4-20-011913",
        "IncidentType": "Vegetation Fire",
        "ResponseDate": 1580279411000,
        "LastUpdate": 1580357356000,
        "Location": "457 Ten Chain Rd, Kinleymore",
        "Region": "4 North Coast Region",
        "Latitude": -26.208141,
        "Longitude": 151.672965,
        "CurrentStatus": "Going",
        "VehiclesOnRoute": 1,
        "VehiclesOnScene": 0,
        "CurrentWarning": "Information",
        "MediaMessage": "There is a vegetation fire at this location. Smoke may affect residents and motorists in the area. Residents should close their doors and windows and keep medication close by if suffering from a respiratory condition. Motorists should use caution and drive to conditions. If you believe your property is under threat, you should call Triple Zero (000) immediately.",
        "FMETimestamp": "20200130142217.4726048",
        "OBJECTID": 1,
        "GlobalID": "5c6e0a07-aa7d-4e80-a44e-b652d2f0f18b",
        "Link": "https://"
      },
      "geometry": {
        "x": 151.672965,
        "y": -26.208141
      }
    },
    {
      "attributes": {
        "Master_Incident_Number": "QF4-20-012241",
        "IncidentType": "Permitted Burn (Attendance)",
        "ResponseDate": 1580353993000,
        "LastUpdate": 1580356129000,
        "Location": "22 Almond Rd, Benarkin North",
        "Region": "4 North Coast Region",
        "Latitude": -26.832734,
        "Longitude": 152.156489,
        "CurrentStatus": "Going",
        "VehiclesOnRoute": 0,
        "VehiclesOnScene": 4,
        "CurrentWarning": "Information",
        "MediaMessage": "There is a vegetation fire at this location. Smoke may affect residents and motorists in the area. Residents should close their doors and windows and keep medication close by if suffering from a respiratory condition. Motorists should use caution and drive to conditions. If you believe your property is under threat, you should call Triple Zero (000) immediately.",
        "FMETimestamp": "20200130142217.4798706",
        "OBJECTID": 2,
        "GlobalID": "2726c898-a6f4-4906-804f-d3f2e6c8a087",
        "Link": "https://"
      },
      "geometry": {
        "x": 152.156489,
        "y": -26.832734
      }
    },
    {
      "attributes": {
        "Master_Incident_Number": "QF6-20-012251",
        "IncidentType": "Vegetation Fire",
        "ResponseDate": 1580354969000,
        "LastUpdate": 1580358095000,
        "Location": "386 Main Western Rd, Tamborine Mountain",
        "Region": "6 South Eastern Region",
        "Latitude": -27.955333,
        "Longitude": 153.182491,
        "CurrentStatus": "Going",
        "VehiclesOnRoute": 2,
        "VehiclesOnScene": 1,
        "CurrentWarning": "Information",
        "MediaMessage": "There is a vegetation fire at this location. Smoke may affect residents and motorists in the area. Residents should close their doors and windows and keep medication close by if suffering from a respiratory condition. Motorists should use caution and drive to conditions. If you believe your property is under threat, you should call Triple Zero (000) immediately.",
        "FMETimestamp": "20200130142217.4813494",
        "OBJECTID": 3,
        "GlobalID": "e310dc73-695c-4466-8dc4-e6eb5344b406",
        "Link": "https://"
      },
      "geometry": {
        "x": 153.182491,
        "y": -27.955333
      }
    },
    {
      "attributes": {
        "Master_Incident_Number": "QF4-20-012274",
        "IncidentType": "Vegetation Fire",
        "ResponseDate": 1580357366000,
        "LastUpdate": 1580357666000,
        "Location": "2-21 Steindl St, Bundaberg East",
        "Region": "4 North Coast Region",
        "Latitude": -24.865996,
        "Longitude": 152.37337,
        "CurrentStatus": "Going",
        "VehiclesOnRoute": 1,
        "VehiclesOnScene": 0,
        "CurrentWarning": "Information",
        "MediaMessage": "There is a vegetation fire at this location. Smoke may affect residents and motorists in the area. Residents should close their doors and windows and keep medication close by if suffering from a respiratory condition. Motorists should use caution and drive to conditions. If you believe your property is under threat, you should call Triple Zero (000) immediately.",
        "FMETimestamp": "20200130142217.4828626",
        "OBJECTID": 4,
        "GlobalID": "a37695bd-ef88-49bd-813a-ca3133d42d83",
        "Link": "https://"
      },
      "geometry": {
        "x": 152.37337,
        "y": -24.865996
      }
    }
  ]
};

const output = input.features.map((obj) => console.log(obj.attributes.Master_Incident_Number, obj.attributes.IncidentType));