JSON.NET exception when deserializing an array of GUIDs

邮差的信 提交于 2019-12-06 04:53:08

You need a wrapper class

string json = "{\"recipeIds\":[\"d9ede305-d244-483b-a435-abcf350efdb2\"]}";
var obj = JsonConvert.DeserializeObject<Wrapper>(json);


public class Wrapper
{
    public Guid[] recipeIds;
}

--EDIT--

Using Linq

var obj = (JObject)JsonConvert.DeserializeObject(json);

var guids = obj["recipeIds"].Children()
            .Cast<JValue>()
            .Select(x => Guid.Parse(x.ToString()))
            .ToList();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!