我有一個C#類,我想轉換爲JSON字符串,將其發送到我的Web客戶端並使用jQuery的,解析成JSON對象的數組。這可能嗎?你可以創建一個JSON字符串,jQuery.each(arg,function(i,val){}可以解析嗎?
這裏是一些示例代碼
class mnuitm
{
public string prop1;
public string prop2;
public List<mnuitm> children;
}
I am trying to build a string that looks like this:
{
"prop1":"value in prop1",
"prop2":"value in prop2",
"children":[
{
"prop1":"value in prop1",
"prop2":"value in prop2"
},
{
"prop1":"value in prop1",
"prop2":"value in prop2"
}
]
}, ... (repeat n times, children may not be there or have any number of child items
} //closing bracket
我的客戶做一個Ajax調用,它返回上述作爲字符串 我試圖使用jQuery解析它,但它不工作。
這是可能的。如果沒有,如何sh我烏爾德做
THX
使用$ .parseJSON(),但我在我的JSON字符串中有幾個錯誤。要找到這些錯誤並解決它們,我使用了JSON Checker,請從http://www.raboof.com/projects/jsonchecker/下載。 – edepperson