gpt4 book ai didi

jQuery - 查找 json 中的某些属性

转载 作者:行者123 更新时间:2023-12-01 08:19:54 24 4
gpt4 key购买 nike

我需要能够识别 JSON 响应的某些属性,这些属性并不总是以相同的方式格式化。该示例的片段如下:

{
"Attributes" : [
{
"Value" : "4 bedrooms",
"DisplayName" : "Bedrooms",
"Name" : "bedrooms"
},
{
"Value" : "2 bathrooms",
"DisplayName" : "Bathrooms",
"Name" : "bathrooms"
},
{
"Value" : "House",
"DisplayName" : "Property type",
"Name" : "property_type"
},
{
"Value" : "$780,000",
"DisplayName" : "Rateable value",
"Name" : "rateable_value"
},
{
"Value" : "Price by negotiation",
"DisplayName" : "Price",
"Name" : "price"
},
{
"Value" : "13 Wellswood Way\r\nLower Shotover\r\nQueenstown-Lakes\r\nOtago",
"DisplayName" : "Location",
"Name" : "location"
},
{
"Value" : "Queenstown-Lakes",
"DisplayName" : "District",
"Name" : "district"
},
{
"Value" : "Lower Shotover",
"DisplayName" : "Suburb",
"Name" : "suburb"
},
{
"Value" : "Otago",
"DisplayName" : "Region",
"Name" : "region"
},
{
"Value" : "254m²",
"DisplayName" : "Floor area",
"Name" : "floor_area"
},
{
"Value" : "1690m²",
"DisplayName" : "Land area",
"Name" : "land_area"
},
{
"Value" : "CBM959",
"DisplayName" : "Property ID#",
"Name" : "property_id"
},
{
"Value" : "playground,tennis,hiking,biking,historic bridge walk,buses,5 mins to shops.",
"DisplayName" : "In the area",
"Name" : "in_the_area"
},
{
"Value" : "Large double garage.Plenty off-street parking.Extra for boat+ etc.",
"DisplayName" : "Parking",
"Name" : "parking"
}
]
}
<小时/>

正如您所看到的,每个属性的名称、显示名称和值都是重复的。我不知道该怎么做就是遍历这些属性来找到特定的属性。例如,我如何获得浴室的值(value)?

感谢您的帮助亚当

最佳答案

示例 -

$(data.Attributes).each(function(index, element){
if(element.Name == 'bathrooms')
console.log(element.Value);
})

演示 - http://jsfiddle.net/PktXh/

关于jQuery - 查找 json 中的某些属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7938388/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com