2013-08-07 18 views
5

'dan gelen web servis geri dönüşümü json verilerini aşağıda verildiği gibi verdim ama istediğim gibi 2. CodeSnipts'ta olduğu gibi. web servis ve sınıflarım aşağıda belirtildiği gibi.Json formatını dönüştürme Webservice

  { "ShowID": 10107, 
      "StartTime": "3:00 PM", 
      "MovieID": 13, 
      "Movie": "Bhaag Milkha Bhaag ", 
      "Screen": "CDC SCreen2", 
      "MediaPath": "bmb1_568962.jpg" 
     },{ "ShowID": 115, 
      "StartTime": "6:00 PM", 
      "MovieID": 13, 
      "Movie": "Bhaag Milkha Bhaag ", 
      "Screen": "CDC SCreen2", 
      "MediaPath": "bmb1_568962.jpg" 
     },{ "ShowID": 110, 
      "StartTime": "9:00 PM", 
      "MovieID": 13, 
      "Movie": "Bhaag Milkha Bhaag ", 
      "Screen": "CDC SCreen2", 
      "MediaPath": "bmb1_568962.jpg" 
     } 

ama istiyorum

[WebMethod] 
public string NowShowingGetList(DateTime ShowDate) 
{ 
    HomeController obj = new HomeController(); 

    JavaScriptSerializer js = new JavaScriptSerializer(); 
    string retJSON = js.Serialize(obj.NowShowingGetList(ShowDate)); 
    return retJSON; 
} 

sınıf obj.NowShowingGetList(ShowDate) burada

public class NowShowingInfo 
{ 
    public int ShowID { get; set; } 
    public string StartTime { get; set; } 
    public int MovieID { get; set; } 
    public string Movie { get; set; } 
    public string Screen { get; set; } 
    public string MediaPath { get; set; } 
} 

olarak dönüş List olarak Webservice

{ 
     "MovieID": 13, 
     "Movie": "Bhaag Milkha Bhaag ", 
     "Screen": "CDC SCreen2", 
     "MediaPath": "bmb1_568962.jpg", 
     "ShowInfo": [ 
      { 
       "ShowID": 10107, 
       "StartTime": "3:00 PM" 
      }, 
      { 
       "ShowID": 115, 
       "StartTime": "6:00 PM" 
      }, 
      { 
       "ShowID": 110, 
       "StartTime": "9:00 PM" 
      } 
     ] 
    } 

benim C# kodu olarak Şimdiden teşekkür ederim.

+1

olarak yeni bir oluşturmak için gereken kişilik başına değişiklikleri yapın sınıf adı ShowInfo ve reklam NowShowingInfo'da d Dizisi veya Listesi. ShowInfo sınıfı özellikler adı içerecektir: ShowId ve StartTime –

+1

ShowInfo'ya yeni bir sınıf adı oluşturmanız ve NowShowingInfo'da Diziyi veya Listeyi eklemeniz gerekir. ShowInfo sınıfı – manoj

cevap

2

Bilgiler içinde

public class NowShowingInfo 
{ 
    public List<ShowInfo> ShowInformation { get; set; } 
    public int MovieID { get; set; } 
    public string Movie { get; set; } 
    public string Screen { get; set; } 
    public string MediaPath { get; set; } 
} 

public class ShowInfo 
{ 
    public int ShowID { get; set; } 
    public string StartTime { get; set; } 
} 

yapmak ilgili değişikliklerdir

public class ShowInfo 
    { 
     public int ShowID { get; set; } 
     public string StartTime { get; set; } 
    } 
    public class NowShowing 
    { 
     public List<ShowInfo> ShowInfo { get; set; } 
     public int MovieID { get; set; } 
     public string Movie { get; set; } 
     public string Screen { get; set; } 
     public string MediaPath { get; set; } 
    } 

ve

public List<NowShowing> NowShowingGetList(DateTime ShowDate) 
    {    
     List<NowShowingInfo> objshowList = obj.NowShowingGetList(ShowDate); 

     int movieID = 0; 
     List<NowShowing> objShowingList = new List<NowShowing>(); 

     NowShowing obj2 = new NowShowing(); 
     ShowInfo objshowInfo = new ShowInfo(); 
     List<ShowInfo> objshowInfoList = new List<ShowInfo>(); 
     int count = 0; 
     string Screen=""; 
     foreach (NowShowingInfo objs in objshowList) 
     { 
      if (movieID != objs.MovieID) 
      { 
       if (count != 0) 
       { 
        obj2.ShowInfo = objshowInfoList; 
        objshowInfoList = new List<ShowInfo>(); 
        objShowingList.Add(obj2); 
        count = 0; 
       } 
       obj2 = new NowShowing(); 
       obj2.MovieID = objs.MovieID; 
       obj2.Movie = objs.Movie; 
       obj2.Screen = objs.Screen; 
       obj2.MediaPath = objs.MediaPath; 

       if (count == 0) 
       { 
        objshowInfo = new ShowInfo(); 
        objshowInfo.ShowID = objs.ShowID; 
        objshowInfo.StartTime = objs.StartTime; 
        objshowInfoList.Add(objshowInfo); 
       } 

      } 
      else 
      { 
       objshowInfo = new ShowInfo(); 
       objshowInfo.ShowID = objs.ShowID; 
       objshowInfo.StartTime = objs.StartTime; 
       objshowInfoList.Add(objshowInfo); 
      } 
      movieID = objs.MovieID; 
      Screen = objs.Screen; 
      count++; 
     } 

     obj2.ShowInfo = objshowInfoList; 
     objShowingList.Add(obj2); 
     return objShowingList; 
    } 
5

sizin webservice

+0

'u nasıl çevirebilirim NowShowingInfo'yu NowShowingInfo'nuza dönüştürebilirim obj.NowShowingGetList (ShowDate) dönüşü NowShowingInfo türümün geri dönüşü – user2641905

+0

Yeni misin? –

+0

newbie demektir @NisargShah – user2641905

İlgili konular