从json中的动态键值获取数据
要求如下:
我必须从页面获取位置字段。
var input= global.input = document.getElementById("Location");
根据输入从json文件中获取邻域区域并显示在页面上。
我有一个 json 对象,并且必须根据键值(位置)从 json 对象中过滤数据
var inputLocation=input.value;
在我的 javascript 中,如果我使用动态键,则会收到错误。
如果我执行此操作,我可以获得 json 数组 data.Aspen
但我必须从文本字段获取数据,并且它可能会有所不同,因此如果我调用 data.inputLocation... 当我使用 data.(inputLocation.value) 时未定义
,出现以下错误:
XML 过滤器应用于非 XML 值 ({Aspen:[{ID:
{
"Aspen":[
{
"ID":"Bellaire",
"Name":"Bellaire"
},
{
"ID":"Champions Forest",
"Name":"Champions Forest"
},
{
"ID":"Highland Village",
"Name":"Highland Village"
},
{
"ID":"Museum District",
"Name":"Museum District"
}
]
}
The requirement is following:
I have to get the location field from page.
var input= global.input = document.getElementById("Location");
Get the neighborhood area from the json file based on input and show on the page.
I have a json object and have to filter the data from the json object based on the key value (location)
var inputLocation=input.value;
In my javascript I am getting the error if I use dynamic the key.
I am able to get the json array if I do this data.Aspen
but i have to get the data from a text field and it can be different so if I call data.inputLocation... its coming undefined
when i use data.(inputLocation.value)
getting the following error :
XML filter is applied to non-XML value ({Aspen:[{ID:
{
"Aspen":[
{
"ID":"Bellaire",
"Name":"Bellaire"
},
{
"ID":"Champions Forest",
"Name":"Champions Forest"
},
{
"ID":"Highland Village",
"Name":"Highland Village"
},
{
"ID":"Museum District",
"Name":"Museum District"
}
]
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用类似数组的语法访问该属性:
如果
inputLocation
设置为"Aspen"
,则与这两行相同:You can access the property using array-like syntax:
If
inputLocation
is set to"Aspen"
, then it is the same as these two lines:从动态 json 对象获取值 使用实时货币转换器 REST API 响应
get value from dynamic json object Using real time currency converter rest api responce