在 jQuery 中序列化爲 JSON [重複] - Serializing to JSON in jQuery [duplicate]

問題:

This question already has answers here : 這個問題在這裏已經有了答案
Closed 4 years ago . 4年前關閉。

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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章