读取字符串时发生JSON.NET错误。意外标记:StartObject。路径';响应数据';,
我试图反序列化这个,但我一直得到这个错误 读取字符串时出错。意外标记:StartObject。路径“响应数据”。 从我谷歌搜索的内容来看,问题似乎是我试图反序列化的对象的设置。下面是我的班级:读取字符串时发生JSON.NET错误。意外标记:StartObject。路径';响应数据';,,json,json.net,Json,Json.net,我试图反序列化这个,但我一直得到这个错误 读取字符串时出错。意外标记:StartObject。路径“响应数据”。 从我谷歌搜索的内容来看,问题似乎是我试图反序列化的对象的设置。下面是我的班级: public class FeedSearchResult { [JsonProperty("responseData")] public String ResponseData { get; set; } [JsonProperty("query")] public
public class FeedSearchResult
{
[JsonProperty("responseData")]
public String ResponseData { get; set; }
[JsonProperty("query")]
public String Query { get; set; }
[JsonProperty("entries")]
public string[] Entries { get; set; }
[JsonProperty("responseDetails")]
public object ResponseDetails { get; set; }
[JsonProperty("responseStatus")]
public String ResponseStatsu { get; set; }
}
public class ResultItem
{
[JsonProperty("title")]
public String Title { get; set; }
[JsonProperty("url")]
public String Url { get; set; }
[JsonProperty("link")]
public String Link { get; set; }
}
我在课堂上做错了什么?非常感谢您的帮助。您的数据模型只有两个嵌套级别,但返回的JSON有三个嵌套级别。如果您使用查看格式化的JSON,您将看到:
{
"responseData":{
"query":"Official Google Blogs",
"entries":[
{
"url":"https://googleblog.blogspot.com/feeds/posts/default",
"title":"\u003cb\u003eOfficial Google Blog\u003c/b\u003e",
"contentSnippet":"\u003cb\u003eOfficial\u003c/b\u003e weblog, with news of new products, events and glimpses of life inside \u003cbr\u003e\n\u003cb\u003eGoogle\u003c/b\u003e.",
"link":"https://googleblog.blogspot.com/"
},
特别是,当数据模型需要成为包含的对象时,它将响应数据
作为字符串
。这是异常的具体原因
如果将JSON上载到,将获得以下数据模型,可用于反序列化此JSON:
public class ResultItem
{
public string url { get; set; }
public string title { get; set; }
public string contentSnippet { get; set; }
public string link { get; set; }
}
public class ResponseData
{
public string query { get; set; }
public List<ResultItem> entries { get; set; }
}
public class RootObject
{
public ResponseData responseData { get; set; }
//Omitted since type is unclear.
//public object responseDetails { get; set; }
public int responseStatus { get; set; }
}
公共类ResultItem
{
公共字符串url{get;set;}
公共字符串标题{get;set;}
公共字符串contentSnippet{get;set;}
公共字符串链接{get;set;}
}
公共类响应数据
{
公共字符串查询{get;set;}
公共列表项{get;set;}
}
公共类根对象
{
公共响应数据响应数据{get;set;}
//由于类型不清楚而省略。
//公共对象响应详细信息{get;set;}
公共int responseStatus{get;set;}
}
您的数据模型与返回的JSON不匹配responseData
是一个对象,但您可以将其作为字符串。将JSON上载到以获得更正的data model.Dang。老实说,我本来应该找一个这样的工具。谢谢你,伙计。