反序列化XML值对于无符号字节来说是太大或太小

时间:2021-04-16 20:21:15

I am downloading transaction data from SagePay using their API. The result from the call gives me an XML string which I then deserialize and store in a class.

我正在使用SagePay的API下载交易数据。调用的结果给了我一个XML字符串,然后我将它反序列化并存储在一个类中。

Each call retrieves the maximum 50 records, I make multiple calls a given datetime span until all records have been retrieved. This works fine for the first X calls but then I get an error:

每个调用检索最大50条记录,我在给定的datetime范围内调用多个调用,直到检索到所有记录为止。这对于第一次X调用很有效,但是之后我得到一个错误:

An unhandled exception of type 'System.InvalidOperationException' occurred in System.Xml.dll

类型系统的未处理异常。发生在System.Xml.dll InvalidOperationException”

Additional information: There is an error in XML document (1, 141).

附加信息:XML文档中有一个错误(1,141)。

Inner Exception: {"Value was either too large or too small for an unsigned byte."}

内部异常:{"值对于无符号字节来说要么太大要么太小。"

The values in XML document (1, 141). do not always remain the same with each try. If I look at the character at this position I can see nothing wrong.

XML文档中的值(1,141)。不要每次尝试都保持不变。如果我观察这个位置上的角色,我不会发现有什么问题。

In this example character 141 is the "t" in <totalrows>:

在本例中,字符141是 中的“t”:

<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><vspaccess><errorcode>0000</errorcode><transactions><startrow>251</startrow><endrow>300</endrow><totalrows>16684</totalrows>

The <startrow> of 251 shows that 5 successful calls have gone before this one that's errored.

251的 显示5个成功的调用在这个错误之前已经消失了。

Deserialize code:

反序列化代码:

XmlSerializer serializer = new XmlSerializer(typeof(vspaccess));
StringReader rdr = new StringReader(xmlDoc.InnerXml);
vspaccess sageTransactions = (vspaccess)serializer.Deserialize(rdr);

vspaccess is the class generated by VS2013 (paste special)

vspaccess是VS2013生成的类(粘贴专用)

What am I missing?

我缺少什么?

I obviously cannot post all the XML as it is live transactional info but if I have missed any required info please let me know

我显然不能发布所有的XML,因为它是实时事务信息,但如果我错过了任何必要的信息,请让我知道

1 个解决方案

#1


5  

read the error. unsigned byte max size is 255 -- so a value of 300 would be to big.

读取错误。无符号字节的最大大小是255——所以300的值是很大的。

16684 would also be to big. don't get hung up on the column number the error reports. look at the error message and what you are loading.

16684年也会大。不要被错误报告的列号所困扰。查看错误消息和正在加载的内容。

#1


5  

read the error. unsigned byte max size is 255 -- so a value of 300 would be to big.

读取错误。无符号字节的最大大小是255——所以300的值是很大的。

16684 would also be to big. don't get hung up on the column number the error reports. look at the error message and what you are loading.

16684年也会大。不要被错误报告的列号所困扰。查看错误消息和正在加载的内容。