编辑 - 我认为解析它是错误的单词,我实际上是想将该文本文件格式化为我提供的格式。
我正在开展一个项目,但我遇到了一个小问题。我需要帮助将文本文件批量编辑为特定格式。我真的不知道该怎么做。例如,以下是文本文件:http://frankerfacez.com/users.txt
具有用户和表情的用户列表(没有句号的用户,有表情的用户)。我需要将其更改为
的格式//user
"emote":["cdn.frankerfacez.com/channel/ user / emote.png"],
供参考,这就是我需要的格式:https://dl.dropboxusercontent.com/u/23313911/CustomEmotes.js
我真的不知道这将是多么容易,或者甚至可能,但任何帮助将不胜感激!
答案 0 :(得分:0)
lines = txtFile.responseText.split("\n");
var user = null;
var emote = null;
var o = {};
for (i in lines) {
var line = lines[i];
if (line.charAt(0) != ".")
user = line;
else {
try{
emote = line.substring(1, line.legth);
var a = new Array();
eval("var cnd = new String('cdn.frankerfacez.com/channel/'+user+'/'+emote+'.png');");
a.push(cnd.toString());
eval("o."+emote+" = a;");
}catch(e){
console.error(emote + " - " + user);
console.error(e);
}
}
}
console.log(o);