Was mache ich hier falsch? Ich versuche, die Ncaa-Daten zu konsumieren, aber ich bekomme eine Menge \ t und \ n in meinen Daten, die es so macht, dass ich es nicht zu einem Objekt serialisieren kann. Hier ist meine Funktion, Sie können dies buchstäblich ausführen, da keine Anmeldeinformationen benötigt werden, um die Daten zu erhalten.API, die eine Reihe von t und n zurückgibt
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);
}
Schweben Sie über Ihre "API" -Tag und lesen Sie die Beschreibung .... –
Was ist der CallbackWrapper umschließt die JSON? Behandeln Sie das schon? – ManoDestra
Während mit '\ t' und' \ n' nichts falsch ist, wenn Sie wirklich nicht damit umgehen können, benutzen Sie einfach ['String.Replace()'] (https://msdn.microsoft.com/de) -us/library/fk49wtc1 (v = vs.110) .aspx) in C# vor dem Versuch, den Text zu analysieren. – abelenky