需要封装的数据
将这些数据,分组出来,OLGoodsID相同的为一组,然后每个组的OLSKUID,放在一个字段里,变成
[{"OLGoodID":"test06261551","OLSKUID":"51112,155111,155113"},{"OLGoodID":"test06261618","OLSKUID":"062611,062612,062613"}]
代码实现:
最后arrGoods的数据就是:
[{"OLGoodID":"test06261551","OLSKUID":"51112,155111,155113"},{"OLGoodID":"test06261618","OLSKUID":"062611,062612,062613"}]
string OLGoodsID = "";
JArray arrGoods = new JArray();
for (int j = 0; j < dtResult.Rows.Count; j++)
{
JObject CurrObjGoods = new JObject();
if (OLGoodsID != dtResult.Rows[j]["OLGoodsID"].ToString())
{
OLGoodsID = dtResult.Rows[j]["OLGoodsID"].ToString();
CurrObjGoods["OLGoodsID"] = dtResult.Rows[j]["OLGoodsID"].ToString();
CurrObjGoods["OLSKUID"]= dtResult.Rows[j]["OLSKUID"].ToString();
arrGoods.Add(CurrObjGoods);
}
else {
arrGoods[arrGoods.Count-1]["OLSKUID"] = arrGoods[arrGoods.Count-1]["OLSKUID"].ToString()+"," + dtResult.Rows[j]["OLSKUID"].ToString();
}
}