传入一个cid,返回一个数组类型数据,在传入数组中的cid,返回子类别数组数据,直到没有子类别
例子:
将:
[
{
"cid","123",
name:"标题1"
},
{
"cid","1234",
name:"标题1"
},
{
"cid","12345",
name:"标题1"
}
]
封装成:
[
{
"cid","123",
name:"标题1",
"child":
[
{
"cid","123",
name:"标题1"
},
{
"cid","1234",
name:"标题1"
},
{
"cid","12345",
name:"标题1"
}
]
},
{
"cid","1234",
name:"标题1"
},
{
"cid","12345",
name:"标题1"
}
]
public JArray GetCID(long CID)
{
ItemcatsGetRequest req_cid = new ItemcatsGetRequest();
req_cid.ParentCid = CID;
req_cid.Fields = "cid,parent_cid,name,is_parent";
ItemcatsGetResponse response_cid = client.Execute(req_cid);
objResult = tbAdmin.XmlToJson(response_cid.Body.ToString(), Rep.Session["UserID"].ToString(), Rep.Request["PlatformID"].ToString(), "获取淘宝商品类目接口");
JArray arrCat = new JArray();
if (objResult["itemcats_get_response"]["item_cats"] != null && objResult["itemcats_get_response"]["item_cats"]["item_cat"] != null)
{
if (CJSON.IsJsonA(objResult["itemcats_get_response"]["item_cats"]["item_cat"].ToString()) && JArray.Parse(objResult["itemcats_get_response"]["item_cats"]["item_cat"].ToString()).Count > 0)
{
arrCat = JArray.Parse(objResult["itemcats_get_response"]["item_cats"]["item_cat"].ToString());
for (int i = 0; i < arrCat.Count; i++)
{
if (arrCat[i]["is_parent"].ToString() == "true")
{
arrCat[i]["child"] = GetCID(long.Parse(arrCat[i]["cid"].ToString()));
}
}
}
else {
JObject objCat = JObject.Parse(objResult["itemcats_get_response"]["item_cats"]["item_cat"].ToString());
if (objCat["is_parent"].ToString() == "true")
{
objCat["child"] = GetCID(long.Parse(objCat["cid"].ToString()));
}
arrCat.Add(objCat);
}
}
return arrCat;
}
public void GetAllCID()
{
JArray arr=GetCID(0);
}