字符串到数组的数组

时间:2013-06-14 17:40:22

标签: javascript ajax

我有一个ajax例程,返回一个看起来像这样的字符串

[["analog.__VG_SPP3_SFRTPCT","analog.__VG_SPP3_SFRTPCT"],
 ["analog._3305_LIST210_1","analog._3305_LIST210_1"],
 ["analog._AG_5340_PR14AN","analog._AG_5340_PR14AN"],
 ["analog._AG_EPNT_2","analog._AG_EPNT_2"],
 ["analog._AG_EPNT_SP","analog._AG_EPNT_SP"],
 ["analog._AG_MERC_ERXTES","analog._AG_MERC_ERXTES"],
 ["analog._AG_ROC_TEST","analog._AG_ROC_TEST"],
 ["analog._AG_ROM1_LOAD","analog._AG_ROM1_LOAD"],
 ["analog._AG_TEST_CRC1LT","analog._AG_TEST_CRC1LT"],
 ["analog._AG_TEST_CRC1RT","analog._AG_TEST_CRC1RT"],
 ["analog._CWAV_TST_MDP1CV","analog._CWAV_TST_MDP1CV"],
 ["analog._CWAV_TST_MDP1CV_LIST","analog._CWAV_TST_MDP1CV_LIST"],
 ["analog._CWAV_TST_MDP2CV","analog._CWAV_TST_MDP2CV"],
 ["analog._CWAV_TST_MDP2CV_LIST","analog._CWAV_TST_MDP2CV_LIST"],
 ["analog._CWAV_TST_MOR1CV","analog._CWAV_TST_MOR1CV"],
 ["analog._CWAV_TST_MOR1CV_LIST","analog._CWAV_TST_MOR1CV_LIST"],
 ["analog._CWAV_TST_MOR2CV_LIST","analog._CWAV_TST_MOR2CV_LIST"],
 ["analog._CWAV_TST_TIME001","analog._CWAV_TST_TIME001"],
 ["analog._CWAV_TST_TIME002","analog._CWAV_TST_TIME002"],
 ["analog._CWAV_TST_TIME003","analog._CWAV_TST_TIME003"]]

将该字符串转换为数组数组的最简单,最快捷的方法是什么,语法实际上与在javascript中定义相同结构的方法相同,是否有办法将其作为javascript执行并获得数组变量呢?

3 个答案:

答案 0 :(得分:3)

这称为JSON

您正在寻找JSON.parse

答案 1 :(得分:1)

您必须使用JSON(Javascript Object Notation)。

类似的东西:

var analogObject = JSON.parse(analogString);

您可以将其转回字符串,然后使用:

var analogString = JSON.stringify(analogObject);

答案 2 :(得分:0)

使用JSON.parse并解析响应文本。这将为您提供阵列数组。