在後臺拆分json
私人?字符串?interactPrizeAll//json?使用字符串接收
方法中的代碼:
Gson?gson?=?新的?gson();
InteractPrize?interactPrize?=新?interact prize();
//gson使用泛型?轉到列表數組?多個對象
列表& ltInteractPrize?& gt?interactPrizeList?=?gson.fromJson(interactPrizeAll,?新的?TypeToken & lt列表& ltInteractPrize & gt& gt(){}.getType());?gson提供的數據類型轉換器TypeToken,可以支持各種數據集類型轉換?
for(int?我?=?0;?我?& lt?interactprizelist . size();?i++)?
{?
interactPrize?=?interactprizelist . get(I);//獲取每個對象
}
此方法在轉換單個對象時使用。
//gson?轉對象?單壹對象
//interactPrize?=?gson.fromJso(interactPrizeAll,interactprize . class);
這個方法就是我後臺拼的json傳到前臺的方式。
jsonStrAll.append("{"+" \ " "+" catid "+" \ " "+":"+" \ "+c . getcatid()+" \ "+","+" \ " "+" cat name "+" \ " ":"+" \ "+c . getcatname()+" \ "+","+?" \ " "+" cat desc "+" \ " "+":"+" \ "+c . getcat desc()+" \ " "+","+" \ " " showinnav "+" " ":"+" "+c . getshowinnav()+" \ " " " " " " "+" sort order "+" \ " " "+":"+" " "+c . getsort order()+" " \ " "+" ","+" level:"+" \ " \ " " " "+" 0 "+" " " "+" " " " " " "自己用!