如何对字符串数据进行分类 javascript
How to classify String data javascript
我想对这个数据主体、标题等进行分类。
{
"offset": "0",
"results": [
{
"body": "A novelist, essayist, historian and critic, Geoff Dyer writes about whatever happens to interest him. ''I am the opposite of an expert,'' he said in an e-mail message, ''a case study in how not to go about building a career as a writer.'' It's been quite a non-career. ''Yoga for People Who Can't Be Bothered to Do It'' won the W. H. Smith Best",
"byline": "By THE EDITORS",
"date": "20071028",
"title": "Up Front",
"url": "http://query.nytimes.com/gst/fullpage.html?res=9E0CE4D61130F93BA15753C1A9619C8B63"
},
{
"body": "PRINCETON, N.J. Many of us have known this scholar: The hair is well-streaked with gray, the chin has begun to sag, but still our tortured friend slaves away at a masterwork intended to change the course of civilization that everyone else just hopes will finally get a career under way. We even have a name for this sometimes pitied species -- the",
"byline": "By JOSEPH BERGER",
"date": "20071003",
"title": "ON EDUCATION; Exploring Ways to Shorten the Ascent to a Ph.D.",
"url": "http://www.nytimes.com/2007/10/03/education/03education.html"
}
]
}
结果
body == {"A novelist, essayist, historian and critic, Geoff Dyer writes about whatever happens to interest him. ''I am the opposite of an expert,'' he said in an e-mail message, ''a case study in how not to go about building a career as a writer.'' It's been quite a non-career. ''Yoga for People Who Can't Be Bothered to Do It'' won the W. H. Smith Best",
"byline": "By THE EDITORS", PRINCETON, N.J. Many of us have known this scholar: The hair is well-streaked with gray, the chin has begun to sag, but still our tortured friend slaves away at a masterwork intended to change the course of civilization that everyone else just hopes will finally get a career under way. We even have a name for this sometimes pitied species -- the"}
byline == ["By THE EDITORS", "By JOSEPH BERGER",}
data == ["20071028", "20071003"]
您必须遍历数据并执行所需的操作(假设它存储在名为 data
的变量中)
for (var i = 0; i < data.results.length; i++) {
console.log(data.results[i].body); //Or whatever you need
..
..
..
}
var data = JSON.parse(json);
var output = {};
for (var i = 0, l = data.results.length; i < l; i++) {
var el = data.results[i];
for (var p in el) {
if (el.hasOwnProperty(p)) {
if (!output[p]) { output[p] = []; }
output[p].push(el[p]);
}
}
}
console.log(output);
相关文章:
- 在检查输入时切换标签分类 javascript
- 根据 Javascript 中子数组的对象对父数组进行重新分类
- 在for循环Javascript中对数字进行分类和计数
- 我无法让我的javascript数字分类器工作
- 在 JavaScript 循环中对对象进行分类
- 使用 javascript 进行数据分类
- 如何对字符串数据进行分类 javascript
- 如何在Javascript中的表分类器中对表列数据进行字母数字排序
- 在 JavaScript 中对关键字进行分类
- 如何使用Javascript在CSS中区分类
- 如何使用Osclass分类广告脚本中的javascript/jquery检测用户是否在主页上
- 我如何使用Javascript“;部分类”;具有TypeScript样式的类定义
- 如何在javascript中对数组进行统计分类
- 使用CSOM和javascript创建分类法子术语
- Javascript将文件分类为图像
- 如何排序教科书的类型,颜色代码,或分类在bookweb使用html, Javascript, CSS或其他
- Javascript分类嵌套函数
- 使用javascript对元素列表进行分类/分组和排序的最佳方法是什么?
- 如何在javascript中对类、函数和函数属性进行分类
- 如何在Javascript中循环遍历对象并按时间戳进行分类