我试图在处理程序中反序列化我的json数据,请看:
context.Response.ContentType = "application/json";
var data = context.Request;
var sr = new StreamReader(data.InputStream);
var stream = sr.ReadToEnd();
var javaScriptSerializer = new JavaScriptSerializer();
var asd = javaScriptSerializer.Deserialize<objEnt>(stream);
我在流中获得了正确的值:比如
"{\"objEnt\":{\"EventName\":\"uyiouioui\",\"EventId\":0,\"Active\":\"1\",\"CountryId\":5,\"StateId\":7,\"CityId\":6,\"Contact\":\"uio\",\"EventVenue\":\"uio\",\"Address\":\"uio\",\"Status\":true,\"Longitude\":\"89\",\"Latitude\":\"89\",\"ShortDesc\":\"ouioui\",\"EventDesc\":\"ouiouio\",\"EventCategoryId\":7,\"StartDate\":\"6/7/2014\",\"EndDate\":\"2014-06-13T18:30:00.000Z\",\"errors\":[],\"FileName\":\"/NightlifeSite/NightlifeClientuploads/Events/\",\"StartTime\":\"12:00 AM\",\"EndTime\":\"12:00 AM\",\"StateName\":\"Karnatka\",\"CityName\":\"Banglore\",\"CountryName\":\"India\",\"EventCategoryName\":\"sadfaewyu\"}}"
但是这些值并没有在我的&#39; asd&#39;每次计数只有零!!
我的objEnt类就像:
[Serializable]
public class objEnt
{
public List<EventEntity> obj { get; set; }
}
[Serializable]
public class EventEntity:Base
{
public string EventName { get; set; }
public string FileName { get; set; }
public int EventId { get; set; }
public int CountryId { get; set; }
public int StateId { get; set; }
|
|
|
more
这真的让DTO课程变得混乱
答案 0 :(得分:0)
使用JSON.NET,您可以尝试这样的事情
var asd = JsonConvert.DeserializeObject<objEnt>(stream);