2012-02-21 43 views
1
{ 
    letter: [{ 
     "description": "aaaa", 
     "date": "19.02.2012 21:34:26", 
     "lid": "6", 
     "companyname": "ml", 
     "personname": "jenny konste", 
     "email": "[email protected]", 
     "fax": "123123", 
     "phone": "345345", 
     "industryname": "finance", 
     "teamname": "b1", 
     "sender": "vivien jacobien", 
     "statusname": "interested"}, 
    { 
     "description": "asdasdadsadsa", 
     "date": "19.02.2012 21:37:03", 
     "lid": "9", 
     "companyname": "ford", 
     "personname": "charles", 
     "email": "[email protected]", 
     "fax": "11111", 
     "phone": "777777", 
     "industryname": "automotive", 
     "teamname": "b3", 
     "sender": "clementine", 
     "statusname": "rejected"}] 
} 
+0

這不是一個有效的JSON – 2012-02-21 10:00:40

回答

2

因爲parseJSON在jQuery的介紹1.4.1你可以使用jQuery的this - JSON庫或者你可以使用JSON.parse()

§EDIT你需要的字符串化將其轉換爲JSON之前的對象。這工作

var json = { 
    letter: [{ 
     "description": "aaaa", 
     "date": "19.02.2012 21:34:26", 
     "lid": "6", 
     "companyname": "ml", 
     "personname": "jenny konste", 
     "email": "[email protected]", 
     "fax": "123123", 
     "phone": "345345", 
     "industryname": "finance", 
     "teamname": "b1", 
     "sender": "vivien jacobien", 
     "statusname": "interested"}, 
    { 
     "description": "asdasdadsadsa", 
     "date": "19.02.2012 21:37:03", 
     "lid": "9", 
     "companyname": "ford", 
     "personname": "charles", 
     "email": "[email protected]", 
     "fax": "11111", 
     "phone": "777777", 
     "industryname": "automotive", 
     "teamname": "b3", 
     "sender": "clementine", 
     "statusname": "rejected"}] 
} 

var parsed = $.secureEvalJSON(JSON.stringify(json)); 
    alert(parsed.letter[1].description); 

小提琴這裏http://jsfiddle.net/5ezyx/

+0

爲什麼我的代碼說它的undefined?成功:功能(味精){ var name = $ .evalJSON(msg).companyname; alert(name); – Codette 2012-02-21 10:33:35

+0

@tfeseas我認爲它使用'JSON.parse()'和'JSON.parse()'解析該json時返回錯誤 – 2012-02-21 10:37:41

+0

我該如何克服這種情況?我能夠通過警報顯示JSON數據,但無法解析它在下一行 – Codette 2012-02-21 11:20:06

0

@tfeseas 在JSON字符串的開頭,我看到letter這是不是在雙引號。這使得JSON無效。也許這就是爲什麼你在解析字符串到對象時遇到問題的原因?

+0

我忘了在這裏更改代碼。在實際json中沒有字母返回。我嘗試我的代碼在fiddler中,它的工作原理,但是當我在本地嘗試它時並沒有。所有代碼都在.ascx文件中,這是一個動態加載到我的主頁的小部件,頁面加載jquery 1.2.6.js.everything工程除了解析部分。 – Codette 2012-02-21 13:27:46

0

對我而言更多。也許有人搜索這個: 使用$ .evalJSON從字符串創建objectData。