我试图解析我的JSON响应,并将其复制/粘贴到Json2CSharp中,然后将2个新生成的类添加到当前类的底部。 (我不喜欢处理多个类)。那我遇到的问题是,当我试图访问生成的类RootObject
我得到的类型的未处理的异常“Newtonsoft.Json.JsonSerializationException”发生在Newtonsoft.Json.dll
用Newtonsoft解析JSON抛出错误的格式错误
错误
附加信息:无法将当前JSON数组(例如[1,2,3])反序列化为类型'Test.RootObject',因为该类型需要JSON对象(例如{“name”:“value”})才能正确地反序列化。
即使语法转换为我,我没有改变它。我需要改变什么,以便这成为有效的可用语法?
static void Main(string[] args)
{
string userid= "186exa";
var url = "https/?rst=" + userid;
var connectionClient = new WebClient();
connectionClient.Headers.Set("H", "XXXXXXXXXXXX");
connectionClient.Headers.Set("uname", "user");
connectionClient.Headers.Set("pswd", "pwd");
var content = connectionClient.DownloadString(url);
}
编辑
这是类 - 将张贴JSON不久
public class List
{
public int id { get; set; }
public string cmu { get; set; }
public int lno { get; set; }
public string clr { get; set; }
public string name { get; set; }
public string origin { get; set; }
public string MajorStyle { get; set; }
public string Style { get; set; }
public string styleImage { get; set; }
public int hid { get; set; }
public string bqty { get; set; }
public int cask { get; set; }
public int local { get; set; }
public string city { get; set; }
}
public class RootObject
{
public string style { get; set; }
public List<List> List { get; set; }
}
这是retunred JSON
[{"Style":"Cajun","List":[{"id":1225,"cmu":"41.2","lno":10,"name":"Bear","origin":"Lake Sinclair, MO","MajorStyle":"Burn Yo Bottom","Style":"","styleImage":"","hid":1,"bqty":"1.00","cask":0,"local":0,"city":"Amsterdam"}
此代码对问题没有用处,请提供类和JSON。 – Simon
请发布您的JSON响应示例。 – Sxntk
@Simon - 更新后的帖子,包括请求的信息。 –