Has anyone had any luck using the .NET DataContractJsonSerializer class to deserialize the LFSWorld pubstat data? I was thinking it would be cool if it worked, but nothing is happening and I'm not getting any error messages. This is the code I'm using, trying to get the PST stats.
That is my data contact, now here is the serialization code.
But as I say I'm getting nothing, no errors or anything, just lots of nulls.
[DataContract]
public class PlayerStats
{
[DataMember(Name = "distance")]
public string Distance { get; set; }
[DataMember(Name = "fuel")]
public string Fuel { get; set; }
[DataMember(Name = "laps")]
public string Laps { get; set; }
[DataMember(Name = "joined")]
public string Joined { get; set; }
[DataMember(Name = "win")]
public string Win { get; set; }
[DataMember(Name = "second")]
public string Second { get; set; }
[DataMember(Name = "third")]
public string Third { get; set; }
[DataMember(Name = "races_finished")]
public string RacesFinished { get; set; }
[DataMember(Name = "qual")]
public string Qual { get; set; }
[DataMember(Name = "pole")]
public string Pole { get; set; }
[DataMember(Name = "drags")]
public string Drags { get; set; }
[DataMember(Name = "dragwins")]
public string DragWins { get; set; }
[DataMember(Name = "country")]
public string Country { get; set; }
[DataMember(Name = "ostatus")]
public string OStatus { get; set; }
[DataMember(Name = "hostname")]
public string HostName { get; set; }
[DataMember(Name = "last_time")]
public string LastTime { get; set; }
[DataMember(Name = "track")]
public string Track { get; set; }
[DataMember(Name = "car")]
public string Car { get; set; }
}
That is my data contact, now here is the serialization code.
public PlayerStats GetPlayerStats(string identKey, string racer)
{
var uri = new Uri(string.Format(@"http://www.lfsworld.net/pubstat/get_stat2.php?version=1.4&idk={0}&action=pst&racer={1}&s=1", identKey, racer));
var request = WebRequest.Create(uri);
var response = request.GetResponse();
using (var stream = response.GetResponseStream())
{
var json = new DataContractJsonSerializer(typeof(PlayerStats));
return json.ReadObject(stream) as PlayerStats;
}
}
But as I say I'm getting nothing, no errors or anything, just lots of nulls.