2016-04-08 25 views
-2

Burada ne yapıyorum? Ncaa verilerini tüketmeye çalışıyorum ama verilerimde \ t ve \ n bir demet alıyorum, bu da onu bir nesneye serileştiremem. İşte benim fonksiyonum, verileri almak için kimlik bilgisi gerektirmediği için bunu tam anlamıyla çalıştırabilirsiniz. bunlar dosyada OLAN çünkü yanıttır içinde \t s ve \n s demet sebebisiniz tümAPI bir grup t döndürüyor ve n

public string GetGameInfo(DateTime dt) 
{ 
    string content = string.Empty; 
    string url = "http://data.ncaa.com/jsonp/scoreboard/baseball/d1/2016/04/06/scoreboard.html"; 
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); 
    request.ContentType = "application/json"; 
    HttpWebResponse response = (HttpWebResponse)request.GetResponse(); 

    Stream resStream = response.GetResponseStream(); 

    using (StreamReader sr = new StreamReader(resStream)) 
    { 
     content = sr.ReadToEnd(); 
    } 


    return content; 
} 


/// <summary> 
/// Summary description for Ncaa 
/// </summary> 
namespace Ncaa 
{ 

    public class callbackWrapper 
    { 
     public List<scoreboard> scoreboard { get; set; } 
    } 
    public class scoreboard 
    { 
     public DateTime day { get; set; } 
     public List<games> games { get; set; } 
    } 

    public class games 
    { 
     public string id { get; set; } 
     public string conference { get; set; } 
     public string gameState { get; set; } 
     public string startDate { get; set; } 
     public string startDateDisplay { get; set; } 
     public string startTime { get; set; } 
     public string startTimeEpoch { get; set; } 
     public string currentPeriod { get; set; } 
     public string finalMessage { get; set; } 
     public string gameStatus { get; set; } 
     public string periodStatus { get; set; } 
     public string downToGo { get; set; } 
     public string timeclock { get; set; } 
     public string network_logo { get; set; } 
     public string location { get; set; } 
     public string contestName { get; set; } 
     public string url { get; set; } 
     public string highlightsUrl { get; set; } 
     public string liveAudioUrl { get; set; } 
     public string gameCenterUrl { get; set; } 
     //public ChampInfo champInfo { get; set; } 
     //public IList<object> videos { get; set; } 
     public home home { get; set; } 
     public away away { get; set; } 
    } 

    public class home 
    { 
     public string teamRank { get; set; } 
     public IList<int> RHEBreakdown { get; set; } 
     public string iconURL { get; set; } 
     public string name { get; set; } 
     public string nameRaw { get; set; } 
     public string nameSeo { get; set; } 
     public string shortname { get; set; } 
     public string color { get; set; } 
     //public Social social { get; set; } 
     public string description { get; set; } 
     public string currentScore { get; set; } 
     public IList<string> scoreBreakdown { get; set; } 
     public string winner { get; set; } 
    } 

    public class away 
    { 
     public string teamRank { get; set; } 
     public IList<int> RHEBreakdown { get; set; } 
     public string iconURL { get; set; } 
     public string name { get; set; } 
     public string nameRaw { get; set; } 
     public string nameSeo { get; set; } 
     public string shortname { get; set; } 
     public string color { get; set; } 
     //public Social social { get; set; } 
     public string description { get; set; } 
     public string currentScore { get; set; } 
     public IList<string> scoreBreakdown { get; set; } 
     public string winner { get; set; } 
    } 

} 

protected void Page_Load(object sender, EventArgs e) 
{ 
    var json = GetGameInfo(DateTime.Now); 

    //this one doesn't work 
    //JsonConvert.DeserializeObject<Ncaa.callbackWrapper>(json); 

    //I tried removing the /ts and ns with no luck too 
    json = json.Replace("\t", string.Empty).Replace("\n", string.Empty); 

    JsonConvert.DeserializeObject<Ncaa.callbackWrapper>(json); 


} 
+1

"API" etiketinizin üzerine gelin ve açıklamayı okuyun .... –

+1

JSON'u kapatan callbackWrapper nedir? Bunu zaten mi yapıyorsun? – ManoDestra

+0

'\ t' ve' \ n' ile ilgili bir sorun yoksa, gerçekten kullanamıyorsanız, ['String.Replace()'] kullanın (https://msdn.microsoft.com/en -us/library/fk49wtc1 (v = vs.110) .aspx) metni ayrıştırmaya çalışmadan önce C# olarak. – abelenky

cevap

1

Öncelikle cevap. Bunlar sırasıyla sekme karakteri ve yeni çizgi karakteridir.

Bunu nasıl ayrıştırdığınızdan emin değilim, ancak çoğu ayrıştırıcı bunu halledebilmelidir. Kendi yazdığınız takdirde lütfen bu kodu gönderin.

Eğer işlev çağrısını şerit ve basitçe NewtonsoftJSON

DÜZENLEME kullanarak JSON ayrıştırmak olabilir callback(JSON) hep biçimi olacaktır iade veriler ise: katma kod inceledikten sonra, seni sıyırma olmadığını fark edebilirsiniz işlev çağrısı. Bunu kaldırmalı ve tekrar denemelisiniz (örneğin, { karakterinin ilk oluşumuna ve sonrasına veya istediğiniz başka bir yola kadar her şeyi kaldırmayı deneyin)

+0

doğru yönde bana sen o zaman özlüyorum şey görebilirsiniz var? actuall içerik 'ya içeriyorsa beri bu, güvensiz olabileceğini –

1

Tamam, ben de çalıştım. Bunu json'a yapmak yardımcı oldu.

Ardından, yalnızca bir geri arama sarmalayıcı nesnesi yerine bir çetele nesnesi olarak ayrıştırma.

+1

Not);. bu son derece düşüktür iken' veya 'callbackWrapper (', aynı zamanda değiştirilecektir, hala kaçınılmalıdır. – Transcendental

İlgili konular