このjsonを逆シリアル化するためのこのコードがありますが、このエラーが発生し続けます:
「System.String型のオブジェクトをNamespace.Models.Url型に変換できません」
。jsonの構造は次のとおりです。
[{fileUrl: "localhost / ContentManager / get / ovYWB0 / 81 / wallpaper"}、{fileUrl: "localhost / ContentManager / get / AcjwO0 / 81 / wallpaper"}、{fileUrl: "localhost / ContentManager / get / HCR0q0 / 81 /wallpaper"}]
私がマッピングしているクラスは次のとおりです。
public class Url { public string FileUrl { get; set; } } public class Response { public Url FileUrl { get; set; } }
デシリアライズコードは次のとおりです。
var serializer = new JavaScriptSerializer();
IList<MTContribute> data = new List<MTContribute>();
var items = serializer.Deserialize<List<Response>>(json);
foreach (var item in items)
{
var newData = new MTContribute
{
DateCreated = DateTime.Today,
IsActive = Convert.ToBoolean("True"),
MTContributeCategoryId = Category.MTContributeCategoryId,
Url = item.FileUrl.FileUrl
};
data.Add(newData);
}