2012-11-07 41 views
0

我的JSON數組:如何將這個JSON數組轉換成列表

{"lstResult":[{"food_photo":[255,216,255,224,0,16,74,70,73,70,0,1........3,5],"food":"12","qty_uom":"Pcs","unit":null}]} 

我的C#類:

public class lstresult 
    { 
    public photo[] lstResult{get;set;} 
    } 

public class photo 
{ 
public byte[] food_photo{get;set;} 
} 
public class Food 
{ 
    public photo[] food_photo { get; set; } 
    public int food_qty { get; set; } 
    public string qty_uom { get; set; } 
    public string unitcost { get; set; } 
} 

我的問題:

我的JSON字符串包含 「food_photo」鍵如何將此字節數組轉換爲 圖像?或轉換成列表在asp.net 預先感謝

回答

0
public class LstFooddtlResult 
{ 
    public List<int> food_photo { get; set; } 
    public string food { get; set; } 
    public string qty_uom { get; set; } 
    public string unitcost { get; set; } 
} 

public class RootObject 
{ 
    public List<LstFooddtlResult> lstResult { get; set; } 
} 
0

使用Javascript Serializer

這裏是使用JavaScript串行

string json = "[{Name:'John Simith',Age:35},{Name:'Pablo Perez',Age:34}]"; 

public class Person 
{ 
    public int Age {get;set;} 
    public string Name {get;set;} 
} 

JavaScriptSerializer js = new JavaScriptSerializer(); 
Person [] persons = js.Deserialize<Person[]>(json); 
+0

一些示例代碼:海我想轉換food_photo在我的JSON字符串中的圖像的關鍵....如何做到這一點? 「 – Narasi

+0

」或轉換爲列表「就是你說的...我總是會很高興向你介紹Javascript串行器:) – Yasser

+0

你想我轉換成列表,但我失敗將food_photo轉換爲列表..顯示空白.. ..當我運行 – Narasi