【发布时间】:2019-11-19 10:25:00
【问题描述】:
我从 api 获取一些数据作为 JSON 响应。这是数据的样例:
Array [
Object {
"cashless_identifier": "N/A",
"controlled_parking_zone": "CA-C",
"disclaimer": "The information provider and/ or licensor are not liable for any errors or omissions contained within this dataset and shall not be liable for any loss, injury or damage caused by its use.",
"easting": "530868",
"epsg_27700_well_known_text_geometry": "LINESTRING (530865.6180417204 181481.26078470872,530863.7711480337 181480.49100505587,530872.4696874953 181460.3867598362,530874.555687954 181461.17653376574)",
"epsg_4326_well_known_text_geometry": "LINESTRING (-0.11531456604058134 51.5171043712184,-0.11534145426089688 51.517097880725345,-0.11522362265321448 51.51691519531169,-0.11519328303934162 51.516921810131386)",
"last_uploaded": "2019-11-18T23:01:51.000",
"latitude": "51.517003",
"location": Object {
"human_address": "{\"address\": \"\", \"city\": \"\", \"state\": \"\", \"zip\": \"\"}",
"latitude": "51.517003",
"longitude": "-0.115284",
},
"longitude": "-0.115284",
"maximum_stay": "N/A",
"nearest_machine": "N/A",
"northing": "181470",
"organisation_uri": Object {
"url": "http://opendatacommunities.org/id/london-borough-council/camden",
},
"parking_bay_length_metres": "22",
"postcode": "WC2A 3PD",
"restriction_type": "taxi rank",
"road_name": "Lincoln's Inn Fields",
"spatial_accuracy": "Defined By Custodian",
"tariff": "N/A",
"times_of_operation": "at any time",
"unique_identifier": "46042626",
"valid_parking_permits": "N/A",
}, .........
数组中返回了许多对象。我的问题是,如何单独访问每个对象?这就是我存储数组的方式:
const [parkingSpaces,setparkingSpaces] = useState([])
setparkingSpaces(response.data)
所以如果我做parkingSpaces.length,这将返回数组的长度。但是,我不知道如何单独访问每个对象及其值。
【问题讨论】:
标签: arrays json react-native