在JSON数组中选择特定项目 [英] selecting a specific item in JSON array
本文介绍了在JSON数组中选择特定项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个JSON对象,当我这样做时:
I have a JSON object that when I do this:
console.log(response.json);
我明白了
{ results:
[ { address_components: [Object],
formatted_address: 'Google Bldg 42, 1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA',
geometry: [Object],
place_id: 'ChIJPzxqWQK6j4AR3OFRJ6LMaKo',
types: [Object] } ],
status: 'OK' }
我希望能够选择formated_address
作为示例.我已经尝试过console.log(response.json.formatted_address);
的变体,但是我不太清楚.
I want to be able to select formated_address
as an example. I've tried variations of console.log(response.json.formatted_address);
that but I can't quite figure it out.
推荐答案
您在数组中有一个对象,因此需要指定数组中的第一项.
You have an object inside an array, so you need to specify the first item in the array.
response.json.results[0].formatted_address
应该工作.
这篇关于在JSON数组中选择特定项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文