5
我有JSON,看起來像這樣在PHP過程JSON響應單個串
json_encode('Test string');
它發回i相螢火檢查的字符串。 我如何訪問它?
success: function(theResponse) {
alert()
}
我該怎麼把裏面的警報拿到那個字符串?
我有JSON,看起來像這樣在PHP過程JSON響應單個串
json_encode('Test string');
它發回i相螢火檢查的字符串。 我如何訪問它?
success: function(theResponse) {
alert()
}
我該怎麼把裏面的警報拿到那個字符串?
你應該格式化你的輸出爲有效的JSON即使它是一個字符串:
json_encode(array("message" => "No Return Email Address Specified!"));
然後你就可以訪問它在JS是這樣的:
success: function(theResponse) {
alert(theResponse.message)
}
使用$響應對象
上success: function(theResponse) {
alert(theResponse.$)
}
JSON不需要像數組或對象那樣的結構。一個字符串的單個實例是有效的JSON。 – 2011-05-10 12:56:32
當然,但如果它是字典那麼應該如何訪問字符串沒有疑問:-) – Xion 2011-05-10 13:02:33