問題:
I need to serialize an object to JSON .我需要將對象序列化爲JSON 。 I'm using jQuery .我正在使用jQuery 。 Is there a "standard" way to do this?有沒有“標準”的方法來做到這一點?
My specific situation: I have an array defined as shown below:我的具體情況:我定義了一個數組,如下所示:
var countries = new Array();
countries[0] = 'ga';
countries[1] = 'cd';
...
and I need to turn this into a string to pass to $.ajax()
like this:我需要把它變成一個字符串傳遞給$.ajax()
像這樣:
$.ajax({
type: "POST",
url: "Concessions.aspx/GetConcessions",
data: "{'countries':['ga','cd']}",
...
解決方案:
參考一: https://en.stackoom.com/question/nur參考二: https://stackoom.com/question/nur