我正在使用一個名爲(http://michaeleisenbraun.com/columns/)的插件將json轉換爲表。將括號添加到json ajax
我使用下面的代碼:
<script>
$.ajax({
url:'/large-data.json',
dataType: 'json',
success: function(json) {
example2 = $('#example2').columns({
data:json,
});
}
});
</script>
它運作良好,當JSON是在括號中,象下面這樣:
[
{
"id": 9998,
"isActive": false,
"balance": "$5",
"age": 38,
"eyeColor": "blue",
"name": "Lola Townsend",
"gender": "female",
"company": "...",
"email": "[email protected],
"phone": "..."
}
]
但是,如果JSON是不是括號也不行,如下所示:
{
"id": 9998,
"isActive": false,
"balance": "$5",
"age": 38,
"eyeColor": "blue",
"name": "Lola Townsend",
"gender": "female",
"company": "...",
"email": "[email protected],
"phone": "..."
}
json響應來自其他網站,所以我將無法控制它是否能夠控制es /沒有括號。
有沒有一種方法可以確保json每次都返回括號,如果不是,那麼括號會被添加?
我試過JSON.parse(),它沒有工作。