在反序列化时,我在json Web服务中得到了字节数组的空值。但是当从浏览器调用时它返回字节数组。 C#代码:
var url = re.DownloadString("XXXX/ListService.svc/lstFooddtl/1/21");
var a = JsonConvert.DeserializeObject<FooddtlResult>(url);
在食物照片中我得到了null ...当我反序列化时...... c#课程:
public class photo
{
public byte[] food_photo { get; set; }
}
public class Food
{
public int food_id { get; set; }
public string food_name { get; set; }
public photo[] food_photo { get; set; }
public string unitcost { get; set; }
}
public class FooddtlResult
{
public Food[] Result { get; set; }
}
{"Result":[{"food_id":"61","food_name":"Idli","food_photo":[255,216,255,224,0,....217],"unitcost":null}]}
答案 0 :(得分:0)
您的模型与JSON不匹配。要正确反序列化,请将Food
类更改为
public class Food
{
public int food_id { get; set; }
public string food_name { get; set; }
public byte[] food_photo { get; set; }
public string unitcost { get; set; }
}
并删除photo
类。
否则,如果你想保留模型结构,那么正确的JSON应该是:
{"Result":[{"food_id":"61","food_name":"Idli","food_photo":[{"food_photo":[255,216,255,224,0,....217]},{"food_photo":[255,...]},...],"unitcost":null}]}