我想从一个活动中发送一个自定义对象到另一个活动中。不知何故,我不能使用Serializable或Parcelable。这就是我正在做的事情。
来自A -> B
Result<String> res = (Result<String>) o;
intent.putExtra("response", new Gson().toJson(res));在B中我是这样做的-
jsonMyObject = intent.getStringExtra("response");
Result<String> temp_result = new Gson().fromJson(jsonMyObject, new TypeToken<Result<String>>() {
}.getType());但它给了我一个错误:需要一个字符串,但在第1行第22列路径BEGIN_ARRAY $.data处发生了错误
发布于 2018-06-22 04:36:18
我自己找到了答案。
我应该在活动B中执行此操作
jsonMyObject = intent.getStringExtra("response");
Result<String> temp_result = new Gson().fromJson(jsonMyObject, Result.class);https://stackoverflow.com/questions/50976920
复制相似问题