I have problems parsing Last.FM API JSON with JSON.NET. The problem is with string values that are meant to be null, like similar an tags in: http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=ASASAS&api_key=53aed44f6fa2ee83d40324232594e1d9&format=json
Otherwise, the object is well-formed: http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=Kamelot&api_key=53aed44f6fa2ee83d40324232594e1d9&format=json
[JsonConverter(typeof(StringNullConverter<Tags>))]
public class Tags
{
public List<Tag> tag { get; set; }
}
internal class StringVacioConverter<T> : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return (objectType == typeof(string)) || (objectType == typeof(List<string>));
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.String)
{
return null;
}
else { return serializer.Deserialize<T>(reader); }
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
}
}
But this, is not working, it enters a infinite loop when tries to return serializer.Deserialize...