2015-06-20 54 views
-2

數組反序列化JSON有一個Web服務,返回一些JSON是這樣的:與項目

{ 
    "ContainerCount": 36, 
    "ContainerUnits": "", 
    "Items": [ 
     { 
      "Id": "GBR|PR|52484481|0|0|0", 
      "Text": "Google UK Ltd, 1 St. Giles High Street, London, WC2H...", 
      "Highlight": "", 
      "Cursor": 0, 
      "Description": "", 
      "Next": "Retrieve" 
     }, 
     { 
      "Id": "GBR|PR|52484493|0|0|0", 
      "Text": "Google UK Ltd, Colonnade Walk, 123 Buckingham Palace Road, London, SW1W...", 
      "Highlight": "", 
      "Cursor": 0, 
      "Description": "", 
      "Next": "Retrieve" 
     }, 
     { 
      "Id": "GBR|PR|28329353|0|0|0", 
      "Text": "Google UK Ltd, Belgrave House, 76 Buckingham Palace Road, London, SW1W...", 
      "Highlight": "", 
      "Cursor": 0, 
      "Description": "", 
      "Next": "Retrieve" 
     }, 
     { 
      "Id": "GBR|PR|52844784|0|0|0", 
      "Text": "Google UK Ltd, 7 Pancras Square, London, N1C...", 
      "Highlight": "", 
      "Cursor": 0, 
      "Description": "", 
      "Next": "Retrieve" 
     }, 
     { 
      "Id": "GBR|PR|50573331|0|0|0", 
      "Text": "Google, Peter House, Oxford Street, Manchester, M1...", 
      "Highlight": "", 
      "Cursor": 0, 
      "Description": "", 
      "Next": "Retrieve" 
     }, 
     { 
      "Id": "GBR|PR|12492688|0|0|0", 
      "Text": "Johnny Goggles, 32 North John Street, Liverpool, L2...", 
      "Highlight": "", 
      "Cursor": 0, 
      "Description": "", 
      "Next": "Retrieve" 
     }, 
     { 
      "Id": "GBR|PR|12682667|0|0|0", 
      "Text": "Jonny Goggles, 274 Stanley Road, Bootle, L20...", 
      "Highlight": "", 
      "Cursor": 0, 
      "Description": "", 
      "Next": "Retrieve" 
     } 
    ] 
} 

我完全不知道如何反序列化JSON這個。

最終目標是在組合框中顯示元素的文本,然後使用組合框選擇的元素的「ID」進一步查詢。

+1

是你想要哪個解串器使用?你有嘗試過什麼嗎? – Plutonix

+0

感謝您將代碼放入代碼塊。 json.net。我不確定如何組織課程。 –

回答

0

創建這些類

public class Container 
    { 
     public IList<Item> Items { get; set; } 
    } 
    public class Item 
    { 
     public string Id { get; set; } 
     public string Text { get; set; } 
    } 

反序列化這樣的:

var container = JsonConvert.DeserializeObject<Container>(json); 

獲取項目:

container.Items 
+0

謝謝。這工作完美。我會投票,但我需要15個聲望來這樣做,而我是一個新手。 –