英文:
How to convert (Object obj) this type of object to JSON and then back?
问题
我尝试了这个:
Gson gson = new Gson();
Log.e("TAGS", "已知人脸额外对象:" + rec.getExtra());
Log.e("TAGS", "已知人脸额外JSON:" + gson.toJson(rec.getExtra()));
Object obj = gson.fromJson(gson.toJson(rec.getExtra()), Object.class);
Log.e("TAGS", "从JSON解析的已知人脸额外对象:" + obj);
我得到的响应是:
已知人脸额外对象:[[F@1f4af8f
已知人脸额外JSON:[[0.0010238411,-0.004055016]]
从JSON解析的已知人脸额外对象:[[0.0010238411, -0.004055016]]
我不确定为什么它无法转换回我所需的对象!
英文:
I tried this:
Gson gson = new Gson();
Log.e("TAGS", "Known Face extra obj: " + rec.getExtra());
Log.e("TAGS", "Known Face extra JSON: " + gson.toJson(rec.getExtra()));
Object obj = gson.fromJson(gson.toJson(rec.getExtra()), Object.class);
Log.e("TAGS", "Known Face extra from JSON: " + obj);
The response what I get is:
Known Face extra obj: [[F@1f4af8f
Known Face extra JSON: [[0.0010238411,-0.004055016]]
Known Face extra from JSON: [[0.0010238411, -0.004055016]]
I'm not sure why it is not converting back to the Object that I need!
答案1
得分: 1
也许你可以尝试在fromJson中指定类型,像这样:
Object obj = gson.fromJson(gson.toJson(rec), double[][].class);
英文:
Maybe you can try to specify the type in fromJson like
Object obj = gson.fromJson(gson.toJson(rec), double[][].class);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论