strJSON =的getContent(URL)ASP的VBScript無法檢測JSON對象
數據返回如下
{"error":{"type":"OAuthException","message":"Error validating access token."}}
然後我可以很容易地檢索它由
set return= JSON.parse(strJSON)
在這裏,我可以很容易地通過以下內容檢索通過內部的所有值
response.write return.error.type
response.write return.error.message
但
如果我response.write return.error.otherobjectnotexist
它會返回錯誤,說Object doesn't support this property or method: 'otherobjectnotexist'
這是很好,當我知道到底是什麼,我會得到回報的對象。
在現實生活中,我們不會知道返回的是什麼,什麼不是。特別是當json從第三方網站返回時。
例如,我使用facebook connect來檢索用戶的打開圖形值並返回爲json。
有些用戶填寫「性別」,所以facebook會返回這個對象。 有些用戶永遠不會填寫「性別」,所以facebook永遠不會返回這個對象。
默認情況下,我的計劃將response.write return.gender
如果我沒有一種方法來檢測對象是否存在與否,以及ASP直接拋出錯誤使得整個程序停止,這將是麻煩......
專家!任何方式來解決這個問題?
爲簡單對象,請參見:HTTP:/ /stackoverflow.com/questions/1278940/list-keys-in-jscript-object-using-vbscript-classic-asp – 2011-01-26 09:00:40