我想选择长度,但它是字符串形式。类似 attribs.length 的东西,但什么也没返回。
attribs: {
"length": ""4"",
"nightride": "null"
}
我尝试过拆分它并重新加入它,但无论哪种方式我都没有得到我想要的。 我也尝试过 attribs[length] 和 attribs["length"] 但无济于事。
这是它的主要 block :
{
places: [
{
city: "Boise",
state: "Idaho",
country: "United States",
name: "Elk Meadows",
parent_id: null,
unique_id: 1637,
directions: ""From Boise's north end (at the intersection of Hill and Bogus Basin roads), travel north up Bogus Basin road about 16.5 miles.the pavement ends at lower (main)parking lot near Bogus Creek Lodge. Proceed on the Boise Ridge Rd. Where the sandy surface turns to pavement as it leavesthe main ridge rd.and splitsright, up through a series of switch backs to the Pioneer Lodge milage starts here",
lat: 43.764,
lon: -116.10324,
description: null,
date_created: null,
children: [ ],
activities: [{
name: "Elk Meadows",
unique_id: "1-118",
place_id: 1637,
activity_type_id: 5,
activity_type_name: "mountain biking",
url: "http://www.singletracks.com/item.php?c=1&i=118",
attribs: {
"length": ""4"",
"nightride": "null"
},
description: "ride east up behind Pioneer Lodge past the tennis courts on your left. the double track becomes more defined",
length: 4,
activity_type: {
created_at: "2012-08-15T16:12:35Z",
id: 5,
name: "mountain biking",
updated_at: "2012-08-15T16:12:35Z"
},
thumbnail: "http://images.singletracks.com/2010/11/Elk-Meadows-on-the-Ranier-0.jpg",
rank: null,
rating: 3
}
]
},
这是我获取该数据的 Angular 尝试:
{{ result.activities[0].attribs["length"] }}
最佳答案
如果 attribs 是一个实际的 javascript 对象并且您想要 attribs.length 的数值
var x = parseFloat(attribs.length.replace(/"/g,''));
关于javascript - 如何选择 key : value pair in string format used in a JSON object?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33139498/