Json 导入失败 - C#
我有以下类结构
public class AreaFields
{
public List<Fields> Fields { set; get; }
}
public class Fields
{
public string Name { set; get; }
public string Value {set; get; }
}
当我使用 Jayrock.Json.Conversion.JsonConvert.ExportToString(List
Jayrock.Json.Conversion.JsonConvert.Import(strJson)
有没有办法可以覆盖导入方法?
编辑:是的,jayrock 知道对象的类型。 我猜它与我序列化列表有关。
Export -
List<AreaField> list = GetAListOfAreaFields();
string sJson = Jayrock.Json.Conversion.JsonConvert.ExportToString(list)
Import -
List<AreaField> list = (AreaField)JsonConvert.Import(typeof(AreaField, sJson);
异常 - 无法从 JSON 数组值导入 AreaField。
I have the following class structure
public class AreaFields
{
public List<Fields> Fields { set; get; }
}
public class Fields
{
public string Name { set; get; }
public string Value {set; get; }
}
When I export to Json using Jayrock.Json.Conversion.JsonConvert.ExportToString(List<AreaField> obj)
, everything works fine. The problem is when I attempt to import it back to a list of AreaField, the native import fails. What I am trying to is
Jayrock.Json.Conversion.JsonConvert.Import(strJson)
Is there a way to maybe override the import method?
EDIT: Yes, jayrock knows the type of the object. My guess it has to do something with me serializing a list.
Export -
List<AreaField> list = GetAListOfAreaFields();
string sJson = Jayrock.Json.Conversion.JsonConvert.ExportToString(list)
Import -
List<AreaField> list = (AreaField)JsonConvert.Import(typeof(AreaField, sJson);
Exception - Cannot import AreaField from a JSON Array value.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看起来您正在导出
List
但尝试导入AreaField
(单数)。 尝试:It looks like you're exporting a
List<AreaField>
but attempting to import anAreaField
(singular). Try:“这不起作用”并不是一个好的开始。 例外? 数据错误? Jayrock 知道物体的类型吗?
"It doesn't work" is not a good start. Exception? Wrong data? Does Jayrock know the type of the object?
列表>> 不起作用,但数组可以。 像这样:
List<> won't works, but array works. Like this: