我无法通过 C# 反序列化 Json 对象。
但是,在反序列化数据时,我收到一条错误消息:
Json Call返回的内容:
[\r\n {\r\n \"postLogoutRedirectUri\": \"https://demo-pec.stage.reds.rxweb-pre.com/services/rxauthlogout\",\r\n \"redirectUri\": \"https://demo-pec.stage.reds.rxweb-pre.com/services/rxauth\"\r\n },\r\n {\r\n \"postLogoutRedirectUri\": \"https://stage.ecommsummitexpo.com/services/rxauthlogout\",\r\n \"redirectUri\": \"https://stage.ecommsummitexpo.com/services/rxauth\"\r\n },\r\n {\r\n \"postLogoutRedirectUri\": \"https://eventportal-new-stage.aem.rxweb-pre.com/services/rxauthlogout\"\r\n }\r\n]
我的 RestSharp 调用:
public Rootobject getRedirectUris(string redirectUriGetUrl)
{
var client = new RestClient(redirectUriGetUrl);
var request = new RestRequest(Method.GET);
request.AddHeader("cache-control", "no-cache");
request.AddHeader("accept", "text/plain");
IRestResponse test = client.Execute(request);
Rootobject object1 = JsonConvert.DeserializeObject<Rootobject>(test.Content); ;
return object1;
}
我的 C# 类(class)
public class Rootobject
{
public RedirectUriGetDto[] redirectUris { get; set; }
}
public class RedirectUriGetDto
{
public string postLogoutRedirectUri { get; set; }
public string redirectUri { get; set; }
}
我收到异常消息:完成读取 JSON 内容后遇到的其他文本:,。路径 '',第 5 行,位置 4。
知道为什么会这样吗?是因为上面不是有效的 Json 吗?
如有任何帮助,我们将不胜感激。
谢谢 罗布
最佳答案
因为你的JSON
数据是一个数组不反对。
你可以尝试使用IEnumerable<RedirectUriGetDto>
而不是 Rootobject
var result = JsonConvert.DeserializeObject<IEnumerable<RedirectUriGetDto>>(test.Content);
关于c# - 无法使用 C# Rest Sharp 反序列化 Json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55966607/