Ekrem Tapan

Ekrem Tapan

  • NA
  • 967
  • 81.2k

How can i Delimite and Group Json value on asp.net

May 23 2016 11:17 PM

I need to delimite and categorize below json value

for ex : "sub3[+]888800" sub3 is category code and 888800 is element of category.

["sub3[+]888800","sub3[+]100000","06[+]888800","06[+]100000"]

i need to result like that

sub3 -> 888800, 100000  06 - > 888800, 100000
  1. List<string> seledItems = this.ResetSeledItems();  
  2.         this.litDebug.Text = Newtonsoft.Json.JsonConvert.SerializeObject(seledItems);  
  3.         var json = this.litDebug.Text;  
  4.         var strs = JArray.Parse(json);  
  5.           
  6.         // process the delimiter  
  7.         var items =  
  8.             from str in strs.Select(x => (string)x)  
  9.             let idx = str.IndexOf("[+]")  
  10.             select new  
  11.             {  
  12.                 tag = str.Substring(0, idx),  
  13.                 data = str.Substring(idx + 3)  
  14.             };  
  15.         // do the grouping  
  16.         var grps =  
  17.             from item in items  
  18.             group item by item.tag into grp  
  19.             select new  
  20.             {  
  21.                 tag = grp.Key,  
  22.                 items = grp.Select(x => x.data)  
  23.             };  
  24.         foreach (var grp in grps)  
  25.         {  
  26.             string tag = grp.tag.ToString();  
  27.               
  28.             for(int i=0;i<=grp.items.Count-1 ; i++)   //grp.items.Count wrong.
  29.             {  
  30.                 string item = grp.items.ToString();  // not get the value. 
  31.             }  
  32.         }  
how can i resolve this problem ?