我有一个巨大的字符串,分为两部分,如下所示:
{\"Query\":\"blabla"","\"Subject\":\"gagaga"}","
{\"Query\":\"lalala\"","\"Subject\":\"rarara\"}","
依此类推......(线条的代表)
我最终需要一个包含这些值的var:
data =“blabla,gagaga”,“lalala,rarara”,....
这是我的代码,但不起作用:
var contentss = JSON.stringify(allFileGenesDetails1);
data="";
var Query1="";
var Subject1="";
// Parse the data
var contentEachLines = contentss.split("\n");
for (var jj = 0; jj < contentEachLines.length; jj++) {
var lineContent = contentEachLines[jj].split("\t");
var divided = lineContent[jj].split(",");
Query1= Query1+ [divided[0]];
Query1 = Query1.replace(/Query|:|{|"|\|/gi, "");
Subject1=Subject1+ divided[1];
Subject1 = Subject1.replace(/Subject|:|{|"|\|/gi, "");
data=data+"'"+ Query1+","+Subject1 +" ' " +"," ;
答案 0 :(得分:-1)
尝试:
var allFileGenesDetails1 = JSON.parse("[{\"Query\":\"blabla\",\"Subject\":\"gagaga\"},{\"Query\":\"lalala\",\"Subject\":\"rarara\"}]");
var data = "";
for(var i = 0; i < allFileGenesDetails1.length; i++) {
if((i+1)==allFileGenesDetails1.length)
data += allFileGenesDetails1[i].Query+","+allFileGenesDetails1[i].Subject;
else
data += allFileGenesDetails1[i].Query+","+allFileGenesDetails1[i].Subject+",";
}
console.log(data);