2012-05-22 70 views
0

我在閱讀C#中的以下JSON輸出時遇到問題。我不是太熟悉JSON語法,但它似乎並沒有被正確格式化,或我不清楚如何正確地反序列化數據:C#問題的JSON反序列化問題

陣列( [標籤] =>列名 [專欄] => column0)

陣列( [0] => 0 [1] =>數組 ( )

[2] => 0) {"total":0,"entities":[],"page":0} 

在C#中使用的代碼只是:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); 
request.Method = WebRequestMethods.Http.Get; 
request.Accept = "application/json"; 
HttpWebResponse response = request.GetResponse() as HttpWebResponse; 
Encoding enc = Encoding.GetEncoding(1252); 
StreamReader configStream = new StreamReader(response.GetResponseStream(), enc); 
var configuration = configStream.ReadToEnd(); 
JavaScriptSerializer jSerialize = new JavaScriptSerializer(); 
List[] operations = jSerialize.Deserialize<List[]>(configuration); 

我收到的錯誤是「陣列」不是一個有效的JSON原語。假設的語法是正確的來自JSON輸出,我該如何派生數據?

回答

0

您的代碼應該能夠正確輸入JSON。您輸入的唯一部分是正確的JSON是:{"total":0,"entities":[],"page":0}

0

在我的Silverlight項目之一,我已經做到這一點:

using Newtonsoft.Json; //add this library to refferences 

ObservableCollection<MyClass> list = JsonConvert.DeserializeObject<ObservableCollection<MyClass>>(json) 

希望這有助於。