使用 JSON 语法实例化锯齿状数组
我有一个 XSD.exe 生成的类。我正在使用一种粗略的控制反转。我的测试对象一直有效,直到我添加了这个奇特的 XML 片段:
<items>
<item>
<model>1000</model>
<description>Torque wrench</description>
<material>1545454</material>
<lot>3</lot>
<serial></serial>
<transferQty>1</transferQty>
<shipQty></shipQty>
</item>
<item>
//..item 2
</item>
<item>
//...item 3
</item>
</items>
</itemOrder>
现在,GeneratedByXsdClass 对象创建失败了。
GeneratedByXsdClass.items = new itemOrderItemsItem[][]{
new itemOrderItemsItem[1][]//this hardcoded 1 bothers me. better way?
{
new itemOrderItemsItem[]
{
new itemOrderItemsItem()
{
model = "1000",
description = "Torque Wrench",
material = "10002525",
lot = "3",
serial = "",
transferQty = "1",
shipQty = ""
}
}
}
};
编译器错误:
Error 3 Cannot implicitly convert type 'itemOrderItemsItem[][]' to 'itemOrderItemsItem[]'
如果可以让生活更轻松,我愿意修改 xsd.exe 生成的类。我真的只想
重复 N 次。
I have an XSD.exe generated class. I am using a crude inversion of control. My test object worked until I added this fancy XML snippet:
<items>
<item>
<model>1000</model>
<description>Torque wrench</description>
<material>1545454</material>
<lot>3</lot>
<serial></serial>
<transferQty>1</transferQty>
<shipQty></shipQty>
</item>
<item>
//..item 2
</item>
<item>
//...item 3
</item>
</items>
</itemOrder>
Now, GeneratedByXsdClass object creation is busted.
GeneratedByXsdClass.items = new itemOrderItemsItem[][]{
new itemOrderItemsItem[1][]//this hardcoded 1 bothers me. better way?
{
new itemOrderItemsItem[]
{
new itemOrderItemsItem()
{
model = "1000",
description = "Torque Wrench",
material = "10002525",
lot = "3",
serial = "",
transferQty = "1",
shipQty = ""
}
}
}
};
Compiler Error:
Error 3 Cannot implicitly convert type 'itemOrderItemsItem[][]' to 'itemOrderItemsItem[]'
I'm open to modifying the xsd.exe generated class if that makes life easier. I really just want <item>
to repeat N times.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将您的示例简化为:
现在您应该能够看到问题所在;您试图将
int[][]
放入int[][]
中,而编译器表示它需要一个int[]
代码>.删除带有注释的行:这与您的代码中的等效内容:
Simplify your example down to this:
Now you should be able to see what the problem is; you're trying to put an
int[][]
inside anint[][]
, and the compiler is saying it expected aint[]
. Remove the line with the comment:This is the equivalent in your code: