我有一个对象pObject
Object pObject = someRpcCall();
我不知道pObject
我所知道的是System.out.println(pObject.toString())
输出
{partner_shipping_id=12, partner_order_id=11, user_id=1, partner_invoice_id=13, pricelist_id=1, fiscal_position=false, payment_term=false}
如何将此pObject转换为以下类的对象
import android.os.Parcel;
import android.os.Parcelable;
public class Customer implements Parcelable {
private int id;
private String name = "";
public Customer() {
// TODO Auto-generated constructor stub
}
/**
* This will be used only by the MyCreator
*
* @param source
*/
public Customer(Parcel source) {
/*
* Reconstruct from the Parcel
*/
id = source.readInt();
name = source.readString();
}
public void setId(int id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return this.id;
}
public String getName() {
return this.name;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(id);
dest.writeString(name);
}
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
@Override
public Customer createFromParcel(Parcel source) {
return new Customer(source);
}
@Override
public Customer[] newArray(int size) {
return new Customer[size];
// TODO Auto-generated method stub
}
};
}
答案 0 :(得分:11)
什么是System.out.println(pObject.getClass().getName());
如果它是相同的Customer
类,那么你可以像这样投射对象
Customer cust = (Customer) pObject;
答案 1 :(得分:0)
提供了上述问题的答案,但是我有一个通用的解决方案,我想与大家分享。
例如:
sleep