【发布时间】:2011-09-20 17:43:43
【问题描述】:
我有一个 Json,我想反序列化并将其保存在类的属性中。但是还没有使用该类进行序列化,是否可以将Json值存储在该类的属性中..
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://api.brightcove.com/services/library?command=find_playlist_by_id&token=myToken&playlist_id=61674080001&video_fields=id,name,thumbnailURL,playsTotal,shortDescription&page_size=1&sort_by=plays_total&sort_order=desc");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (StreamReader reads = new StreamReader(response.GetResponseStream()))
{
value = reads.ReadToEnd();
}
value = value.Remove(1, value.IndexOf("]") + 1);
hidField.Value = value;
JavaScriptSerializer s = new JavaScriptSerializer();
BCVideos v = s.Deserialize<BCVideos>(value);
存储 Json 数据的类。
public class BCVideos
{
private int _id;
public int Id
{
get { return _id; }
set { _id = value; }
}
private string _name, _thumbnailUrl, _shortDescription;
public string ShortDescription
{
get { return _shortDescription; }
set { _shortDescription = value; }
}
public string ThumbnailUrl
{
get { return _thumbnailUrl; }
set { _thumbnailUrl = value; }
}
public string Name
{
get { return _name; }
set { _name = value; }
}
}
如果有人做过这种工作,请回复。
【问题讨论】:
标签: asp.net json deserialization