Javascript Array/JSON Library
Javascript Array/JSON Library
基本上,我需要某种库/函数集,允许我在数组上执行高级函数。
例如:var jsondata = "SearchResponse":{ "Version":"2.0","Query":{
"SearchTerms":"sushi"},"Web":{ "Total":15000000,"Offset":0,"Results":[
{ "Title":"Sushi - Wikipedia, the free encyclopedia","Description":"In
Japanese cuisine, sushi (寿司, 鮨, 鮓, sushi?) is vinegared rice, usually
topped with other ingredients, including fish (cooked or uncooked) and
vegetables.","Url":"http:'/'/en.wikipedia.org'/wiki'/Sushi","DisplayUrl
":"http:'/'/en.wikipedia.org'/wiki'/Sushi","DateTime":"2008-06-
09T06:42:34Z"}]}} /* pageview_candidate */}
var filterdata = filter(jsondata, {"Title":"Sushi - Wikipedia, the free encyclopedia"});
然后filterdata
将包含jsondata中标题为Sushi - Wikipedia, the free encyclopedia
看一下underscore.js。您可能无法编写与您的问题完全相同的代码,但它接近于它:
_.filter(jsondata.Web.Results, function (val) {
return val.Title === "Sushi - Wikipedia, the free encyclopedia";
});
首先,jsondata
是一个对象,而不是一个数组;然而,jsondata.Web.Results
属性是一个数组。考虑到这一点,您可以使用JavaScript数组。过滤方法。
var results = jsondata.Web.Results.filter(function (value) {
// Return true if you want this 'value' object to appear in the 'results' Array.
return (value.Title === "Sushi - Wikipedia, the free encyclopedia");
});
如果你想对数组做更严肃的工作,那么包含一个集合框架将是明智的;JavaScript中最流行的是underscore.js。对集合的深刻理解将为你未来的编程生涯带来好处。
看看PHP.js。
相关文章:
- jQuery匹配JSON对象的部分文本
- 在循环中分配json值时,值被覆盖
- 需要帮助设置json数组
- 如何在Javascript中将JSon对象转换为数组
- 我可以在json对象中添加一个函数吗
- 使用JS将数组转换为json对象
- Javascript-如何读取json文件中的列并将其保存在Javascript数组中
- 使用JQuery解析JSON嵌套数组
- 在使用Polymer'加载所有json文件后执行方法;s的核心ajax
- 如何使用json将对象列表从java转换为javascript
- 如何使用 node.js 比较两个 json 数组
- 如何将JSON数据导入我的ejs模板
- 区分JSON中的矩阵和列表列表
- 不显示带有本地json文件数据的谷歌地图脚本
- 如何将json数据显示为html
- 如何为json对象中的段发送array[]
- 根据id将json数组组合为一个json数组
- Json数据包含日期和时间格式
- AngularJS-在JSON选择器中使用变量名
- Javascript Array/JSON Library