反序列化在C#中一个Java序列化的文件 [英] Deserializing a java serialized file in C#

查看:192
本文介绍了反序列化在C#中一个Java序列化的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有一个序列化的一些对象和整数与功能的文件中像

I have a have a java project that serializes some objects and ints to a file with functions like

ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeInt(RANK_SIZE);
oos.writeObject(_firstArray);
oos.writeObject(_level[3]);
oos.writeObject(_level[4]);
...

现在我有麻烦反序列化的C#该文件(试过的BinaryFormatter ),因为它显然只能反序列化整个文件到一个单一的对象(或数组,但我有不同的lenghts不同的对象)。

Now I have trouble deserializing that file with C# (tried the BinaryFormatter) as it apparently can only deserialize the whole file into a single object (or arrays, but I have different objects with different lenghts).

我第一次尝试端口这些文件到C#的产生,但悲惨地失败了。这些文件是小,我不的必须生成它们自己。

I tried first to port the generation of these files to C#, but failed miserably. These files are small and I don't must to generate them myself.

我是否需要更改这些文件在Java中生成的方式或者我可以反序列化以任何方式?

Do I need to alter the way those files are generated in Java or can I deserialize it in any way?

推荐答案

有没有在它知道如何反序列化Java对象的标准.NET架构。您的可能的,从理论上讲,使用Java序列化规范和C#编写自己的代码反序列化。不过,这将是一个庞大而复杂的工程,我不认为你会发现兴趣使用它众多的客户。

There is nothing in the standard .NET framework which knows how to deserialize Java objects. You could, in theory, use the Java serialization spec and write your own deserialization code in C#. But it would be a large and complex project, and I don't think you'd find many customers interested in using it.

很远,很容易将改变序列化数据的方式使用便携式格式:JSON,或某种形式的XML。有Java和C#的库来处理这种格式,总的努力将是数量级以下。我会极大地倾向于第二种方法。

Far, far easier would be to change the way you serialize the data to use a portable format: JSON, or some form of XML. There are both Java and C# libraries to deal with such formats and the total effort would be orders of magnitude less. I would vastly prefer this second approach.

这篇关于反序列化在C#中一个Java序列化的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆