Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
120 views
in Technique[技术] by (71.8m points)

javascript - 如何在JavaScript或jQuery中过滤JSON数据?(How to filter JSON Data in JavaScript or jQuery?)

How to filter JSON data using Javascript or jQuery?(如何使用Javascript或jQuery过滤JSON数据?)

This my JSON data:(这是我的JSON数据:) [{"name":"Lenovo Thinkpad 41A4298","website":"google"}, {"name":"Lenovo Thinkpad 41A2222","website":"google"}, {"name":"Lenovo Thinkpad 41Awww33","website":"yahoo"}, {"name":"Lenovo Thinkpad 41A424448","website":"google"}, {"name":"Lenovo Thinkpad 41A429rr8","website":"ebay"}, {"name":"Lenovo Thinkpad 41A429ff8","website":"ebay"}, {"name":"Lenovo Thinkpad 41A429ss8","website":"rediff"}, {"name":"Lenovo Thinkpad 41A429sg8","website":"yahoo"}] JavaScript:(JavaScript的:) obj1 = JSON.parse(jsondata); now I only want name and website data which is contain website is equal to "yahoo"(现在我只想要包含网站的名称和网站数据等于“雅虎”)   ask by Me7888 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is how you should do it : ( for google find)(这是你应该这样做的:(谷歌查找))

$([ {"name":"Lenovo Thinkpad 41A4298","website":"google222"}, {"name":"Lenovo Thinkpad 41A2222","website":"google"} ]) .filter(function (i,n){ return n.website==='google'; }); Better solution : ( Salman's)(更好的解决方案:(萨尔曼)) $.grep( [{"name":"Lenovo Thinkpad 41A4298","website":"google"},{"name":"Lenovo Thinkpad 41A2222","website":"google"}], function( n, i ) { return n.website==='google'; }); http://jsbin.com/yakubixi/4/edit(http://jsbin.com/yakubixi/4/edit)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...