我怎样才能通过像查询这样的JSON数组来获得价值 [英] How can I get value through JSON array like query
问题描述
我有一个Json数组:
computers:
[
{
id:1,
type:laptop,
manufactor:
[
{
id:m_1,
名称:HP
},
{
id:m_2,
名称:Sony
}
]
id:2,
type:desktop,
manufactor:
[
{
id:m_3,
名称:Apple
},
{
id:m_4,
名称:Tiger
}
]
}
]
你能告诉我我怎么能这样做:加载计算机数据>>获取2计算机ID 1和2 >>选择计算机ID = 1 >>加载该计算机的制造商。
我可以用mysql查询做到这一点,但在json中,我不知道该怎么做。
感谢您的建议!
编辑:我想从上面的JSON对象中检索ID为1的计算机制造商。
感谢大家帮助我。
我打算创建一个使用JSON的页面,就像DOJOX滚动列表一样,你会给我示例还是建议如何做到这一点?
谢谢:D
使用:
computers [0] .manufactor [0] .name
返回HP。
如果您将其更改为:
电脑[0] .manufactor [1] .name
您将获得Sony。
进一步更改为:
computers [1] .manufactor [0] .name
将返回Apple。
最后:
computers [0] .manufactor [0] .name
返回Tiger。 /www.json.org/js.html\">更多有关如何使用Javascript处理JSON对象的信息。
Sorry for my English. I have a Json Array :
"computers":
[
{
"id": 1,
"type": "laptop",
"manufactor":
[
{
id: "m_1",
name: "HP"
},
{
id: "m_2",
name: "Sony"
}
]
},
{
"id": 2,
"type": "desktop",
"manufactor":
[
{
id: "m_3",
name: "Apple"
},
{
id: "m_4",
name: "Tiger"
}
]
}
]
Could you tell me how can I do it like this: load computers data >> get 2 computer id 1 and 2 >> choose computer id = 1 >> load the manufactor of that computer. I can do it with mysql query but in json i don't know how to do that. Thanks for Suggestion!
Edit: I want to retrieve the manufacturer of the computer with ID - 1 from the JSON object above.
Thank to everyone for helping me out. I am going to create a page working with JSON look like DOJOX Rolling list, would you give me example or suggestion how to do like that ? thank you:D
Using:
computers[0].manufactor[0].name
Will return "HP".
If you change it to:
computers[0].manufactor[1].name
You will get "Sony".
Changing it further to:
computers[1].manufactor[0].name
will return "Apple".
And finally:
computers[0].manufactor[0].name
returns "Tiger".
Look here for more information on how to manipulate JSON objects with Javascript.
这篇关于我怎样才能通过像查询这样的JSON数组来获得价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!