C# 序列化Json数组,在NewtonSoft Json中可以实现单Json多Json错误
将错误作为 阅读完JSON内容后遇到的其他文本:,。 路径“”,第1行,位置203。Newtonsoft.Json.JsonTextReader.Read() (at:0) !!!我不会把它传给数组C# 序列化Json数组,在NewtonSoft Json中可以实现单Json多Json错误,c#,json,unity3d,C#,Json,Unity3d,将错误作为 阅读完JSON内容后遇到的其他文本:,。 路径“”,第1行,位置203。Newtonsoft.Json.JsonTextReader.Read() (at:0) !!!我不会把它传给数组 [ { "Code": "0002", "Name": "Inspire #9898", "size": "10x10", "Company": "inspire", "Description1": "Textu
[
{
"Code": "0002",
"Name": "Inspire #9898",
"size": "10x10",
"Company": "inspire",
"Description1": "Textured Grey HighQuality",
"Description2": "Fit For Kitchen,Bathroom and PlayArea Floor",
"Price": "250",
"Type": "1"
},
{
"Code": "0004",
"Name": "Inspire #98101",
"size": "10x10",
"Company": "inspire",
"Description1": "Textured Grey HighQuality",
"Description2": "Fit For Kitchen,Bathroom and PlayArea Floor",
"Price": "250",
"Type": "3,1"
}
]
您需要将
JSON
字符串反序列化为列表
:
型号:
[System.Serializable]
public class RootObject
{
public string Code { get; set; }
public string Name { get; set; }
public string size { get; set; }
public string Company { get; set; }
public string Description1 { get; set; }
public string Description2 { get; set; }
public string Price { get; set; } public string Type { get; set; }
}
公共类根对象
{
公共字符串代码{get;set;}
公共字符串名称{get;set;}
公共字符串大小{get;set;}
公共字符串公司{get;set;}
公共字符串描述1{get;set;}
公共字符串描述2{get;set;}
公共字符串Price{get;set;}
公共字符串类型{get;set;}
}
var rt=JsonConvert.DeserializeObject(www.text);
你能分享你的RootObject吗
对不起,我是个新手,但它遇到了一个错误:“List”不包含“code”的定义,并且无法找到可访问的扩展方法“code”接受类型为“List”的第一个参数使用System.Collections.Generic导入代码>已经在使用,问题是我想序列化对象列表,,,@akhilesh您能给我们展示一下这个过程的全部代码吗?上面的答案将把你的JSON
字符串反序列化为你的模型
asList
'[System.Serializable]公共类RootObject{public string code{get;set;}公共字符串名称{get;set;}公共字符串大小{get;set;}公共字符串公司{get;set;}公共字符串描述1{get;set;}公共字符串描述2{get;set;}公共字符串价格{get;set;}公共字符串类型{get;set;}'
[System.Serializable]
public class RootObject
{
public string Code { get; set; }
public string Name { get; set; }
public string size { get; set; }
public string Company { get; set; }
public string Description1 { get; set; }
public string Description2 { get; set; }
public string Price { get; set; } public string Type { get; set; }
}
public class RootObject
{
public string Code { get; set; }
public string Name { get; set; }
public string size { get; set; }
public string Company { get; set; }
public string Description1 { get; set; }
public string Description2 { get; set; }
public string Price { get; set; }
public string Type { get; set; }
}
var rt = JsonConvert.DeserializeObject<List<RootObject>>(www.text);