好吧,我有以下html表:
<table id="people" border="1">
<thead>
<tr>
<th>Name</th>
<th>Places</th>
<th>Grade</th>
</tr>
</thead>
<tbody>
<tr>
<td>Oscar</td>
<td>New York</td>
<td>16.5</td>
</tr>
<tr>
<td>Antonio</td>
<td>
<p>New York</p>
<p>Chicago</p>
<p>Toronto</p>
</td>
<td>14</td>
</tr>
<tr>
<td>Jessica</td>
<td>New York</td>
<td>19</td>
</tr>
</tbody>
现在当我使用jquery tableToJson函数时,我得到了这个输出:
[
{"Name":"Oscar","Places":"New York","Grade":"16.5"},
{"Name":"Antonio","Places":"New York\n\t\t\tChicago\n\t\t\t\tToronto","Grade":"14"},
{"Name":"Jessica","Places":"New York","Grade":"19"}
]
现在看看Antonio,创建的功能
{"Name":"Antonio","Places":"New York\n\t\tChicago\n\t\t\t\tToronto","Grade":"14"}
但不是
\ n
我希望地方也像这样显示为JSON数组:
{"Name":"Antonio","Places":["New York","Chicago","Toronto"],"Grade":"14"}
我知道这里描述的选项(https://github.com/lightswitch05/table-to-json),但我不知道使用哪个或如何使用它们,因为它没有真正记录,如何详细使用它们
任何帮助都会非常感激: - )
答案 0 :(得分:1)
如果您想更新现有阵列,请尝试使用此
var places = [
{"Name":"Oscar","Places":"New York","Grade":"16.5"},
{"Name":"Antonio","Places":"New York\n Chicago\n Toronto","Grade":"14"},
{"Name":"Jessica","Places":"New York","Grade":"19"}
];
for(var x=0;x<places.length;x++){
places[x].Places = places[x].Places.split("\n");
}
console.log(places);