在JSON中搜索EmpName [英] Search an EmpName in JSON
问题描述
我创建了一个包含一些数据的json文件,例如
[
{empid:2307535,empname: shekhar},
{empid:2307536,empname:smith},
{empid:2307537,empname:john },
{empid:2307544,empname:james}
]
为此,每当我写empid然后我应该得到empname以及验证也像
如果max-length< 7 || min-length> 5 ==错误
以及我需要检查这个empid意味着如何检查输入的empid是否是corect。
请尽快回复。
谢谢。
I have created a json file with some data like
[
{"empid":2307535, "empname":"shekhar"},
{"empid":2307536, "empname":"smith"},
{"empid":2307537, "empname":"john"},
{"empid":2307544, "empname":"james"}
]
for this , whenever I write empid then I should get empname as well as validation also like
if max-length<7 || min-length>5 == error
as well as I need to check this empid means how to check whether entered empid is corect or not.
Please reply asap.
thanks.
推荐答案
如果你正在使用JQuery,你可以循环
If you are using JQuery, you can do a loop
.each(json,function(i,v){
if (v.empid == mySearchString){
// 做东西
}
});
.each(json, function(i, v) { if (v.empid == mySearchString) { //Do stuff } });
这篇关于在JSON中搜索EmpName的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!