2014-09-23 54 views
0

我正在关注可帮助将我的google电子表格提取到json文件http://blog.pamelafox.org/2013/06/exporting-google-spreadsheet-as-json.html的教程。但是我有一些google电子表格单元格中的对象列表。我的一个电子表格就是这样的:screenshot http://www.tianyuwu.com/wp-content/uploads/2014/09/Screen-Shot-2014-09-22-at-11.46.00-PM.png谷歌电子表格导出到json文件,如何格式化?

我的专家是让这样的json文件。

{ 
     "features": "*articles\n*archive\n*video\n*search\n*social", 
     "data": "*news feeds\n*oroeco team", 
     "content": "* blog posts\n* analysis\n* screen shots", 

    } 

但我希望是这样

{ 
      "features": "articles","archive","video", "search", "social", 
      "data": "news feeds","oroeco team", 
      "content": "* blog posts","analysis", "screen shots", 

     } 

什么是转换的最有效的方法是什么?

回答

1

如果你正在使用JavaScript,试试这个:

json_original = { 
    "features" : "*articles\n*archive\n*video\n*search\n*social", 
    "data" : "*news feeds\n*oroeco team", 
    "content" : "* blog posts\n* analysis\n* screen shots", 
} 

json_formated = {} 
for (var p in json_original) { 
    json_formated[p] = json_original[p].replace('\n', '').split('*').map(function(x) { return x.trim(); }).filter(function(x) {return x != ''; }); 
}