- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试使用 json 格式的文件作为输入。这是示例数据的片段。
[
{
id: 1671349531,
name: "A Wild Restaurant Expansion",
blurb: "We are looking to expand from our current location to a new and better facility. One that will be available for our our followers!",
goal: 17000,
pledged: 0,
state: "live",
slug: "a-wild-restaurant-expansion",
disable_communication: false,
country: "US",
currency: "USD",
currency_symbol: "$",
currency_trailing_code: true,
deadline: 1425185940,
state_changed_at: 1422373209,
created_at: 1422141288,
launched_at: 1422373209,
backers_count: 0,
photo: {
full: "https://s3.amazonaws.com/ksr/projects/1619167/photo-full.jpg?1422144440",
ed: "https://s3.amazonaws.com/ksr/projects/1619167/photo-ed.jpg?1422144440",
med: "https://s3.amazonaws.com/ksr/projects/1619167/photo-med.jpg?1422144440",
little: "https://s3.amazonaws.com/ksr/projects/1619167/photo-little.jpg?1422144440",
small: "https://s3.amazonaws.com/ksr/projects/1619167/photo-small.jpg?1422144440",
thumb: "https://s3.amazonaws.com/ksr/projects/1619167/photo-thumb.jpg?1422144440",
1024x768: "https://s3.amazonaws.com/ksr/projects/1619167/photo-1024x768.jpg?1422144440",
1536x1152: "https://s3.amazonaws.com/ksr/projects/1619167/photo-1536x1152.jpg?1422144440"
},
creator: {
id: 602131664,
name: "Chef James Nelson",
avatar: {
thumb: "https://s3.amazonaws.com/ksr/avatars/13830182/logo3.thumb.jpg?1422143536",
small: "https://s3.amazonaws.com/ksr/avatars/13830182/logo3.small.jpg?1422143536",
medium: "https://s3.amazonaws.com/ksr/avatars/13830182/logo3.medium.jpg?1422143536"
},
urls: {
web: {
user: "https://www.kickstarter.com/profile/602131664"
},
api: {
user: "https://api.kickstarter.com/v1/users/602131664?signature=1422460143.21cd79c238aeae43e8a4311c18bf8e8cd2c3a39a"
}
}
},
location: {
id: 2433186,
name: "Kissimmee",
slug: "kissimmee-fl",
short_name: "Kissimmee, FL",
displayable_name: "Kissimmee, FL",
country: "US",
state: "FL",
type: "Town",
is_root: false,
urls: {
web: {
discover: "https://www.kickstarter.com/discover/places/kissimmee-fl",
location: "https://www.kickstarter.com/locations/kissimmee-fl"
},
api: {
nearby_projects: "https://api.kickstarter.com/v1/discover?signature=1422447847.04d19a9efbe31a0d300969276d5d6f5ffa88a776&woe_id=2433186"
}
}
},
category: {
id: 312,
name: "Restaurants",
slug: "food/restaurants",
position: 9,
parent_id: 10,
urls: {
web: {
discover: "http://www.kickstarter.com/discover/categories/food/restaurants"
}
}
},
urls: {
web: {
project: "https://www.kickstarter.com/projects/602131664/a-wild-restaurant-expansion?ref=newest",
rewards: "https://www.kickstarter.com/projects/602131664/a-wild-restaurant-expansion/rewards"
}
}
},
{
id: 267033207,
name: "The Razors Edge ~ (based on the book Giggling in Fairmont).",
blurb: "An indie film to follow up on the recently published book. In it's first few weeks of release it has taken a strong grip on the world.",
goal: 5000,
pledged: 0,
state: "live",
slug: "the-razors-edge-based-on-the-book-giggling-in-fair",
disable_communication: false,
country: "US",
currency: "USD",
currency_symbol: "$",
currency_trailing_code: true,
deadline: 1424964564,
state_changed_at: 1422372564,
created_at: 1421465861,
launched_at: 1422372564,
backers_count: 0,
photo: {
full: "https://s3.amazonaws.com/ksr/projects/1599522/photo-full.jpg?1421465884",
ed: "https://s3.amazonaws.com/ksr/projects/1599522/photo-ed.jpg?1421465884",
med: "https://s3.amazonaws.com/ksr/projects/1599522/photo-med.jpg?1421465884",
little: "https://s3.amazonaws.com/ksr/projects/1599522/photo-little.jpg?1421465884",
small: "https://s3.amazonaws.com/ksr/projects/1599522/photo-small.jpg?1421465884",
thumb: "https://s3.amazonaws.com/ksr/projects/1599522/photo-thumb.jpg?1421465884",
1024x768: "https://s3.amazonaws.com/ksr/projects/1599522/photo-1024x768.jpg?1421465884",
1536x1152: "https://s3.amazonaws.com/ksr/projects/1599522/photo-1536x1152.jpg?1421465884"
},
creator: {
id: 198971258,
name: "Jesse Gerken",
avatar: {
thumb: "https://s3.amazonaws.com/ksr/avatars/12370207/author_pic.thumb.jpg?1411309933",
small: "https://s3.amazonaws.com/ksr/avatars/12370207/author_pic.small.jpg?1411309933",
medium: "https://s3.amazonaws.com/ksr/avatars/12370207/author_pic.medium.jpg?1411309933"
},
urls: {
web: {
user: "https://www.kickstarter.com/profile/198971258"
},
api: {
user: "https://api.kickstarter.com/v1/users/198971258?signature=1422460143.dd7e5606db2806a10e516e1def16575c3aae41e1"
}
}
},
location: {
id: 2401584,
name: "Fairmont",
slug: "fairmont-wv",
short_name: "Fairmont, WV",
displayable_name: "Fairmont, WV",
country: "US",
state: "WV",
type: "Town",
is_root: false,
urls: {
web: {
discover: "https://www.kickstarter.com/discover/places/fairmont-wv",
location: "https://www.kickstarter.com/locations/fairmont-wv"
},
api: {
nearby_projects: "https://api.kickstarter.com/v1/discover?signature=1422448035.58aff9025d72453411d574df4707a417d4b7b970&woe_id=2401584"
}
}
},
category: {
id: 297,
name: "Horror",
slug: "film & video/horror",
position: 10,
parent_id: 11,
urls: {
web: {
discover: "http://www.kickstarter.com/discover/categories/film%20&%20video/horror"
}
}
},
urls: {
web: {
project: "https://www.kickstarter.com/projects/198971258/the-razors-edge-based-on-the-book-giggling-in-fair?ref=newest",
rewards: "https://www.kickstarter.com/projects/198971258/the-razors-edge-based-on-the-book-giggling-in-fair/rewards"
}
}
},
{
id: 1791731386,
name: "PulseAuction",
blurb: "Seeking promotional funding for PulseAuction.com - a PATENTED online auction site. We've banished Per-Bid Fees! Join The Revolution.",
goal: 7000,
pledged: 0,
state: "live",
slug: "pulseauction",
disable_communication: false,
country: "US",
currency: "USD",
currency_symbol: "$",
currency_trailing_code: true,
deadline: 1424964553,
state_changed_at: 1422372553,
created_at: 1419635170,
launched_at: 1422372553,
backers_count: 0,
photo: {
full: "https://s3.amazonaws.com/ksr/projects/1559949/photo-full.jpg?1421250474",
ed: "https://s3.amazonaws.com/ksr/projects/1559949/photo-ed.jpg?1421250474",
med: "https://s3.amazonaws.com/ksr/projects/1559949/photo-med.jpg?1421250474",
little: "https://s3.amazonaws.com/ksr/projects/1559949/photo-little.jpg?1421250474",
small: "https://s3.amazonaws.com/ksr/projects/1559949/photo-small.jpg?1421250474",
thumb: "https://s3.amazonaws.com/ksr/projects/1559949/photo-thumb.jpg?1421250474",
1024x768: "https://s3.amazonaws.com/ksr/projects/1559949/photo-1024x768.jpg?1421250474",
1536x1152: "https://s3.amazonaws.com/ksr/projects/1559949/photo-1536x1152.jpg?1421250474"
},
creator: {
id: 835111372,
name: "WW Pulse Inc. dba PulseAuction.com",
avatar: {
thumb: "https://s3.amazonaws.com/ksr/avatars/13524481/rick_head_shot_Cleaned.thumb.jpg?1420034475",
small: "https://s3.amazonaws.com/ksr/avatars/13524481/rick_head_shot_Cleaned.small.jpg?1420034475",
medium: "https://s3.amazonaws.com/ksr/avatars/13524481/rick_head_shot_Cleaned.medium.jpg?1420034475"
},
urls: {
web: {
user: "https://www.kickstarter.com/profile/835111372"
},
api: {
user: "https://api.kickstarter.com/v1/users/835111372?signature=1422460143.e75af1301e433dc803f3f929249d0c45ce3eaebd"
}
}
},
location: {
id: 23689683,
name: "South Florida",
slug: "south-florida-fl",
short_name: "South Florida, FL",
displayable_name: "South Florida, FL",
country: "US",
state: "FL",
type: "Town",
is_root: false,
urls: {
web: {
discover: "https://www.kickstarter.com/discover/places/south-florida-fl",
location: "https://www.kickstarter.com/locations/south-florida-fl"
},
api: {
nearby_projects: "https://api.kickstarter.com/v1/discover?signature=1422447780.143e234a4af62e7d8366fad3b204044920bcbc66&woe_id=23689683"
}
}
},
category: {
id: 342,
name: "Web",
slug: "technology/web",
position: 15,
parent_id: 16,
urls: {
web: {
discover: "http://www.kickstarter.com/discover/categories/technology/web"
}
}
},
urls: {
web: {
project: "https://www.kickstarter.com/projects/835111372/pulseauction?ref=newest",
rewards: "https://www.kickstarter.com/projects/835111372/pulseauction/rewards"
}
}
}
是否可以在 r 中使用这种复杂的 json 格式制作 csv,以便更平滑地处理数据?
例如有以下基本类别:基本信息照片创造者地点类别网址
是否可以制作一个包含基本信息.id、creator.id 等子类别类别的 csv 文件?
最佳答案
另一种无需 json-2-csv 的实现,可以处理复杂数据:
// Some complex demo data
var data = [
{
"id": "111",
"name": "Johny Smith",
"age": "23",
"dates": [
{
"birthday": "01.01.1990",
"nameday": "02.02",
"phone": {
"home": "02123123123123",
"mobile": "07124123123",
}
}
]
},
{
"id": "222",
"name": "Jane Alex",
"age": "43",
"dates": [
{
"birthday": "06.06.1997",
"nameday": "03.03",
"phone": {
"home": "029999999999999",
"mobile": "0788888888",
}
}
]
}
];
// Converted string ready to be downloaded as csv
var converted = toCsv(data);
// This is used to automatically generate and download the .CSV file
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(converted));
element.setAttribute('download', "Output.csv");
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
//////////////////////////////////// THE MAGIC -> ////////////////////////////////////
function toCsv(arr) {
arr = pivot(arr);
return arr.map(function (row) {
return row.map(function (val) {
return isNaN(val) ? JSON.stringify(val) : +val;
}).join(',');
}).join('\n');
}
function toConsumableArray(arr) {
if (Array.isArray(arr)) {
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) {
arr2[i] = arr[i];
}
return arr2;
} else {
return Array.from(arr);
}
}
function pivot(arr) {
var mp = new Map();
function setValue(a, path, val) {
if (Object(val) !== val) {
// primitive value
var pathStr = path.join('.');
var i = (mp.has(pathStr) ? mp : mp.set(pathStr, mp.size)).get(pathStr);
a[i] = val;
} else {
for (var key in val) {
setValue(a, key == '0' ? path : path.concat(key), val[key]);
}
}
return a;
}
var result = arr.map(function (obj) {
return setValue([], [], obj);
});
let outcome = ([[].concat(toConsumableArray(mp.keys()))].concat(toConsumableArray(result)));
return outcome;
}
参见 JS Fiddle -> https://jsfiddle.net/gbktnd1j/
关于javascript - 将 json 转换为 csv 格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28175276/
我正在尝试将一个字符串逐个字符地复制到另一个字符串中。目的不是复制整个字符串,而是复制其中的一部分(我稍后会为此做一些条件......) 但我不知道如何使用迭代器。 你能帮帮我吗? std::stri
我想将 void 指针转换为结构引用。 结构的最小示例: #include "Interface.h" class Foo { public: Foo() : mAddress((uint
这有点烦人:我有一个 div,它从窗口的左上角开始过渡,即使它位于文档的其他任何位置。我试过 usign -webkit-transform-origin 但没有成功,也许我用错了。有人可以帮助我吗?
假设,如果将 CSS3 转换/转换/动画分配给 DOM 元素,我是否可以检测到该过程的状态? 我想这样做的原因是因为我正在寻找类似过渡链的东西,例如,在前一个过渡之后运行一个过渡。 最佳答案 我在 h
最近我遇到了“不稳定”屏幕,这很可能是由 CSS 转换引起的。事实上,它只发生在 Chrome 浏览器 上(可能还有 Safari,因为一些人也报告了它)。知道如何让它看起来光滑吗?此外,您可能会注意
我正在开发一个简单的 slider ,它使用 CSS 过渡来为幻灯片设置动画。我用一些基本样式和一些 javascript 创建了一支笔 here .注意:由于 Codepen 使用 Prefixfr
我正在使用以下代码返回 IList: public IList FindCodesByCountry(string country) { var query =
如何设计像这样的操作: 计算 转化 翻译 例如:从“EUR”转换为“CNY”金额“100”。 这是 /convert?from=EUR&to=CNY&amount=100 RESTful 吗? 最佳答
我使用 jquery 组合了一个图像滚动器,如下所示 function rotateImages(whichHolder, start) { var images = $('#' +which
如何使用 CSS (-moz-transform) 更改一个如下所示的 div: 最佳答案 你可以看看Mozilla Developer Center .甚至还有例子。 但是,在我看来,您的具体示例不
我需要帮助我正在尝试在选中和未选中的汉堡菜单上实现动画。我能够为菜单设置动画,但我不知道如何在转换为 0 时为左菜单动画设置动画 &__menu { transform: translateX(
我正在为字典格式之间的转换而苦苦挣扎:我正在尝试将下面的项目数组转换为下面的结果数组。本质上是通过在项目第一个元素中查找重复项,然后仅在第一个参数不同时才将文件添加到结果集中。 var items:[
如果我有两个定义相同的结构,那么在它们之间进行转换的最佳方式是什么? struct A { int i; float f; }; struct B { int i; float f; }; void
我编写了一个 javascript 代码,可以将视口(viewport)从一个链接滑动到另一个链接。基本上一切正常,你怎么能在那里看到http://jsfiddle.net/DruwJ/8/ 我现在的
我需要将文件上传到 meteor ,对其进行一些图像处理(必要时进行图像转换,从图像生成缩略图),然后将其存储在外部图像存储服务器(s3)中。这应该尽可能快。 您对 nodejs 图像处理库有什么建议
刚开始接触KDB+,有一些问题很难从Q for Mortals中得到。 说,这里 http://code.kx.com/wiki/JB:QforMortals2/casting_and_enumera
我在这里的一个项目中使用 JSF 1.2 和 IceFaces 1.8。 我有一个页面,它基本上是一大堆浮点数字段的大编辑网格。这是通过 inputText 实现的页面上的字段指向具有原始值的值对象
ScnMatrix4 是一个 4x4 矩阵。我的问题是什么矩阵行对应于位置(ScnVector3),旋转(ScnVector4),比例(ScnVector3)。第 4 行是空的吗? 编辑: 我玩弄了
恐怕我是 Scala 新手: 我正在尝试根据一些简单的逻辑将 Map 转换为新 Map: val postVals = Map("test" -> "testing1", "test2" -> "te
输入: This is sample 1 This is sample 2 输出: ~COLOR~[Green]This is sample 1~COLOR~[Red]This is sam
我是一名优秀的程序员,十分优秀!