如何使用拆分产品数组字符串,并将键值对保存在字典或列表中。串在cookie是:拆分字符串数组并将键值对存储在列表或字典中
cookieValue ="12&150&pid=1,name=abc,size=2gm Sachet,price=50,image=Pouch.jpg,quantity=1&pid=2,name=xyz,size=200gm Packet,price=50,image=small.jpg,quantity=2"
产品阵列是如下:
[0] "12"
[1] "150"
[2] "pid=1,name=abc,size=2gm Sachet,price=50,image=Pouch.jpg,quantity=1"
[3] "pid=2,name=xyz,size=200gm Packet,price=50,image=small.jpg,quantity=2"
代码进行处理的Cookie:
if(HttpContext.Request.Cookies["Cart"]!= null)
{
var cookieValue = Request.Cookies["Cart"].Value;
string[] products = cookieValue.Split('&');
var len = products.Length;
for(int x=2;x<=len;x++)
{
string s1 = products[x];
}
}
什么是_Key_ = 12的_Value_部分? – Steve
Dictionary keyValuePairs = s1.Split(','); –
shweta
我只是想把第二和第三个数组的值字符串分开使用(,) – shweta