通过Ajax调用SP,返回一个字符串。
var AjaxData = $.ajax({
type: "POST",
contentType: "application/json;",
url: "WebForm1.aspx/GetHeartBeatData",
data: "{}",
dataType: "JSON",
async: false
}).responseText;
var MyTest = JSON.parse("[" + AjaxData + "]");
SP会回复我期待看到的内容,但是当它通过Ajax"它回来了
AjaxData "{"d":"[[\"Time\",\"DB1\",\"DB2\",\"DB3\",\"DB4\"],[\"1:00\",54,50,57,47],[\"2:00\",56,46,63,20],[\"3:00\",46,48,45,49],[\"4:00\",60,38,76,23],[\"5:00\",2,34,82,15],[\"6:00\",40,42,39,43],[\"7:00\",66,26,94,55],[\"8:00\",68,22,100,39],[\"9:00\",34,36,33,37],[\"10:00\",72,14,12,5],[\"11:00\",85,10,18,105],[\"12:00\",28,30,27,31],[\"13:00\",79,38,30,88],[\"14:00\",101,38,36,14],[\"15:00\",22,24,21,25],[\"16:00\",85,38,49,39],[\"17:00\",67,38,55,42],[\"18:00\",16,18,15,19],[\"19:00\",91,38,67,22],[\"20:00\",53,38,73,0],[\"21:00\",10,12,9,13],[\"22:00\",97,38,85,0],[\"23:00\",9,38,91,39]]"}" String
当它执行JSON.parse(AjaxData)时,它会将MyTest创建为一个数组,除了MyTest [0]元素有一个'子类别' proto 和d,其中MyTest [0] .d是我要查找的数据,但它是一个字符串。我将此提供给GoogleChart,GoogleChart需要一个阵列。如何让MyTest [0]元素成为有问题的数组?
答案 0 :(得分:2)
你只有一步之遥:
var myArray = JSON.parse(MyTest[0].d);