1.java代碼
為了解決Map不支持序列化的問題,
特意定義了一個(gè)數(shù)組(里面用到了List來(lái)做轉(zhuǎn)換)
迎合序列化的需要
@Expose
@XStreamAlias("TheFroms")
@SerializedName("TheFroms")
public OrderFromInfo[] theFroms;
@Expose
@XStreamAlias("Froms")
@SerializedName("Froms")
public Map Froms;
private Map froms = new HashMap();
/**
* new一個(gè)List來(lái)做Map數(shù)組的轉(zhuǎn)換
*Author:shaorongfei
* @return new
*/
public OrderFromInfo[] getTheFroms() {
List theItems = new ArrayList();
if (froms != null) {
for (OrderFromInfo orderFromInfo : froms.values()) {
theItems.add(orderFromInfo);
}
}
final int size = theItems.size();
theFroms = (OrderFromInfo[]) theItems.toArray(new OrderFromInfo[size]);
return theFroms;
}
/**
* 迎合序列化需要,數(shù)組等同F(xiàn)roms屬性。
* Author:shaorongfei
* @param theFroms 傳入的OrderFromInfo[]數(shù)組
*/
public void setTheFroms(OrderFromInfo[] theFroms) {
froms = new HashMap();
for (OrderFromInfo item : theFroms) {
froms.put(item.getRftype(), item);
}
}
public Map getFroms() {
return froms;
}
public void setFroms(Map froms) {
this.froms = froms;
}
2.C#代碼
以上需要的朋友可以借此來(lái)試一試,在做Xml序列化時(shí)項(xiàng)目里經(jīng)常會(huì)用到。
本文標(biāo)題:.net和java中不支持字典的序列化的變通方法
網(wǎng)址分享:
http://weahome.cn/article/poccph.html