2011-05-04 78 views
0

請幫我解釋下我需要做什麼?我需要這條消息,在他們的專用字符串 ,但我不知道如何去做C#/ Json.net /如何反序列化消息?

也如何使用字典?

,我收到的消息是這樣的..其稱爲sServerResponse

字符串中
{"pcname": "Kat", "pause": [], "ip": "192.168.1.100", "paused": 0, "services": [], "session": "", "shop": [], "end": 0, "used": 0, "start": 0, "timeup": 0, "follow": "sui", "consq": {"1": "basic", "3": "rounding", "2": "minimum"}, "stas": 0, "price": 0, "pc_status": 1, "account_details": {"3": "Member", "2": "Staff/Member", "4": "Timecode"}, "msg": "Connection/Update accepted.", "mac": "00112233445", "others": [], "remarks": "", "ticker": {"units": 1}, "fixed_time": [], "account": "", "pause_tmp": {"s": 0, "e": 0}, "ver": {}, "status_details": {"1": "Idle", "0": "Offline", "5": "Fixed", "4": "Open", "7": "Mem", "6": "Extended", "8": "Timecode"}, "cmd": "nothing", "load": 0, "deposit": [], "data": {"fixed": [], "open": 0}, "restirctions": {"start_button": 0, "keys": [{"ctrl-esc": 0}, {"alt-tab": 0}], "mouse": 1, "drives": [{"c": 0}, {"d": 0}], "desktop": 0, "task_manager": 0, "keyboard": 1, "taskbar": 0, "control_panel": 0}} 

請指導我..無數谷歌的香港專業教育學院取得和主題我已閱讀。 上json.net didnt樣品甚至工作

編輯/ UPDATE:

現在我想這一個

List<WrapperReader> datas; 

datas = new JavaScriptSerializer(new SimpleTypeResolver()).Deserialize<List<WrapperReader>>(jsonInput); 

}

但DATAS是空的,可能是什麼問題在這裏?

更新2

我種的身影什麼使它錯誤

其類。

如果即將接收字符串數組。然後在我的班級我必須宣佈它作爲數組 同樣去小數和日期

關於日期..如果我要去接收日期。我如何聲明它,以便它可以包含日期?

即時通訊將完成編碼看看其真正的罪魁禍首

回答

0


我爲你寫一個基本的例子。 你可以使用沒有Json.NET庫。

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Web.Script.Serialization; 

namespace ConsoleApplication1 
{ 
public class Customer 
{ 
    public int CustomerID { get; set; } 
    public string CustomerName { get; set; } 
    public string CustomerSurname { get; set; } 

    public override string ToString() 
    { 
     return this.CustomerID + " " + this.CustomerName + " " + this.CustomerSurname; 
    } 
} 

class Program 
{ 
    static void Main(string[] args) 
    { 
     string JSonData = @"[ 
     { 
      ""CustomerID"": ""1"", 
      ""CustomerName"": ""Mehmet"", 
      ""CustomerSurname"": ""Tasköprü"" 
     }, 
     { 
      ""CustomerID"": ""2"", 
      ""CustomerName"": ""Cin"", 
      ""CustomerSurname"": ""Ali"" 
     }, 
     { 
      ""CustomerID"": ""3"", 
      ""CustomerName"": ""Temel"", 
      ""CustomerSurname"": ""Reis"" 
     }]"; 

     IList<Customer> iListData = new JavaScriptSerializer().Deserialize<IList<Customer>>(JSonData); 

     foreach (var item in iListData) 
      Console.WriteLine(item.ToString()); 

     Console.Read(); 
    } 
} 

}

+0

喜三江源的例子,它是有用的,我做我自己的反序列化 – Katherina 2011-05-06 14:56:51