[英]convert string to json array
我從Ajax請求中得到了這個響應。 Javascript似乎將其解釋為字符串。 (當我說警告this.responseText時,顯示整個字符串)
我怎樣才能將它轉換為javascript對象(JSON)?
{"response": {
"success": "The activity has been removed",
"message": "0"
}
}
我不是在使用jquery。
如果你使用jQuery, JSON.parse(this.responseString);
或jQuery.parseJSON(this.responseString);
應該管用。
這不是世界上最安全的事情,但你可以這樣做:
var value = null, txt = this.responseText;
eval("value = (" + txt + ")");
這樣做可能會更安全一些:
var value = null, txt = this.responseText;
!function(window) { eval("value = (" + txt + ")"); }();
但仍有各種潛在的黑客攻擊。 你最好使用圖書館。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.