从json数组中获取逗号分隔的数组

时间:2014-05-04 17:27:26

标签: jquery asp.net-mvc

JS

var arrSpecialInstructions = [];
arrSpecialInstructions.push("sder");
arrSpecialInstructions.push("vfgtr");
$.ajax(
{
    url: "/PetBooking/CreditCardBookingProcess/",
    data:
    {
        'arrSpecialInstructions': JSON.stringify(arrSpecialInstructions)
    },
    type: 'POST',
    success: function (data, status, xhr) {},
    error: function (xhr, textStatus, errorThrown) {}
});

行动方法

[HttpPost]
public ActionResult CreditCardBookingProcess(string arrSpecialInstructions)
{
    var specialInstructionsArray = arrSpecialInstructions.Split(',');
}

我只需要检索逗号分隔的字符串数组。但是它给出如下所示。如何在分割它之后得到像sder,vfgtr这样的简单字符串数组。此时此刻它还有很多其他字符。

enter image description here

1 个答案:

答案 0 :(得分:1)

无需使用join()进行字符串化:

data: { 'arrSpecialInstructions': arrSpecialInstructions.join() },