2011-09-20 2 views
0

나는 Json을 가지고, 내가 deserialize하고 클래스의 속성 안에 저장 싶어요. 하지만, 그 클래스를 사용하여 직렬화되지 않았 기억 JSON 데이터asp.net에서 Json Deserializing

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; } 
    } 

} 

누구든지 이런 종류의 작업을 수행 한 경우 회신하여주십시오.

답변

0

질문을 따르기가 꽤 어렵지만, BrightCove의 API를 올바르게 기억하면 BrightCove 비디오 컬렉션을 여기에서 만들고 싶습니다. 따라서 필요한 것은 두 개의 레이어가있는 객체입니다. 하나의 컨테이너에는 동영상 배열이있는 재생 목록이 있습니다. 용기를 가리고있는 것뿐입니다.

public class BrightCovePlayList 
{ 
    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; } 
    } 

    public Video[] Videos {get; set; } 
} 

public class Video 
{ 
    public int Id {get; set;} 
    public string Name {get; set;} 
    //properties as appropriate. 
} 

PS : 그것은처럼 보일 것이다 당신은 아마 여기에 원시 webrequests보다는 Hammock 또는 적어도 System.Net.WebClient 같은 것을 사용하고 싶습니다. Json.net은 JavaScriptSerializer보다 훨씬 나은 직렬화 라이브러리이기 때문에 볼 수도 있습니다.

관련 문제