string s = "['1','1|1'],['2','2|2'],['3','3|3'],['4','4|4']";
如何把这样的字符串转换成二维数组
string s = "['1','1|1'],['2','2|2'],['3','3|3'],['4','4|4']";
var array = System.Text.RegularExpressions.Regex.Split(s, @"(?<=\]),(?=\[)").Select(t => Regex.Matches(t, @"(?<=')\d[^']*(?=')").Cast<Match>().Select(st => st.Value).ToArray()).ToArray();
第一步:先把"["去除. s=s.replace("[","");
第二部:用split分割成数组string []arr=s.split("],");
第三部:新建一个二维数组,把值填进去,string [,] str= new string[arr.length,2];
....
using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes("[['1','1|1'],['2','2|2'],['3','3|3'],['4','4|4']]".Replace("'","\"")))) { System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(Array)); Array obj = (Array)serializer.ReadObject(ms); }