2013-06-21 39 views
2

我通過分析在我的jQuery文件JSON對象創建爲無法反序列化JSON對象字典

{"showmiddleinitial":"True","showprefix":"True","showsuffix":"True"} 

現在我米使用AJAX調用發送該對象到我的控制器,它

$.parseJSON({"showmiddleinitial":"True","showprefix":"True","showsuffix":"True"}) 

{"showmiddleinitial":"True","showprefix":"True","showsuffix":"True"} 

對於上述兩種情況我得到的後續錯誤

Cannot deserialize JSON object into type 'System.Collections.Generic.List`1[System.Collections.Generic.Dictionary`2[System.String,System.String]]'. 

Error converting value "{"showmiddleinitial":"True","showprefix":"True","showsuffix":"True"}" to type 'System.Collections.Generic.List`1[System.Collections.Generic.Dictionary`2[System.String,System.String]]'. 

任何一個可以引導我正確的方向? 我米使用ASP.net使用C#,MVC和jQuery

我不能做我的C#代碼更因爲這是靜態的,所以我不得不只能依靠jQuery的。 在C#中的對象的類型

List<Dictionary<string, string>> attributesList 

嘛......我到問題的底部,並指出發送

$.parseJSON([{"showmiddleinitial":"True","showprefix":"True","showsuffix":"True"}]) 

解決問題。 任何一個可以請讓我知道如何方括號從jQuery的添加到JSON對象着,當然不manualy

+1

嘗試'JSON.stringify(param)'.. –

+0

http://stackoverflow.com/questions/9058656/cannot-deserialize-json-object-into-type-system-collections-generic-list – musicnothing

回答

0

您的JSON字符串值應該用引號引起來裹得像個

string json = @"{""key1"":""value1"",""key2"":""value2""}"; 

加入他們,然後調用

Dictionary<string, string> values = JsonConvert.DeserializeObject<Dictionary<string, string>>(json); 
+1

我想方形需要大括號[{「showmiddleinitial」:「 True「,」showprefix「:」True「,」showsuffix「:」True「}],解決了目的 – Gautam