如何将Java对象转换为C ++对象? [英] How to convert a Java object into a C++ object?

查看:452
本文介绍了如何将Java对象转换为C ++对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是这样的。我已经将存储在文件中的二进制Java对象序列化。我需要在C ++中重构对象,并做进一步的处理。

My problem is like this. I have serialized binary Java objects stored in files. I need to reconstruct the objects in C++ and do further process.

我想我可以反序列化Java对象使用Java,序列化到acsii文件,然后加载C ++代码。另外,我知道可以使用JNI从C ++调用Java函数,但是我不知道如何传递参数,即将对象返回到C ++。但是有更好的方法吗?

I think I can deserialize the Java objects using Java, serialize again into acsii files, then load in C++ code. Also, I know it's possible to call Java function from C++ using JNI, but I don't know how to pass parameters, i.e., return the objects back to C++. But is there a better way?

谢谢!

推荐答案

可以直接打开序列化文件,并从C ++获取数据。您可以查看规范,但我建议您开始阅读一篇文章,如 Java序列化算法显示

You can open the serialized files direcly and pickup the data from C++. You can see the specification but I recomend to start reading an article like The Java serialization algorithm revealed.

但对我来说,更好的方法是再次加载对象到Java中,并使用类似 google-gson 或其他人。

But the easier and for me the better way is to load the objects in Java again and Serialize it to JSON with a java library like google-gson or others.

这篇关于如何将Java对象转换为C ++对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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