我有我的JSON值從Java來解析JSON字符串,如需要使用JavaScript
var obj = "[{"id":"58","str":"sd <p/> Comment By Smith John on 2012-10-30"},{"id":"58","str":"sd <p/> Comment By Smith John on 2012-10-30"},{"id":"58","str":"sd <p/> Comment By Smith John on 2012-10-30"},{"id":"58","str":"sd <p/> Comment By Smith John on 2012-10-30"},{"id":"58","str":"sd <p/> Comment By Smith John on 2012-10-30"},{"id":"58","str":"sd <p/> Comment By Smith John on 2012-10-30"},{"id":"58","str":"sd <p/> Comment By Smith John on 2012-10-30"},{"id":"58","str":"sd <p/> Comment By Smith John on 2012-10-30"}] ".
我想使用jQuery爲$ .parseJSON(OBJ)來分析;
我收到錯誤爲未定義。我想獲得id值。
我收錄了jquery-ui.js和jquery.js。
我檢查了jsonlint並將其作爲有效的json。含有"
字符
你是如何訪問它的ID ...這是一個對象數組,你可以通過你如何試圖訪問ID。 –
你試過了什麼請發表呢? – sunleo
請顯示您的JS代碼。如果您正在使用jQuery的Ajax函數來檢索此對象(如問題中的「jquery-ajax」標記所暗示的那樣),那麼您不應該使用'$ .parseJSON()',因爲jQuery將解析字符串爲你,並將所得到的對象(本例中是一個數組)傳遞給你提供的回調函數。 – nnnnnn