#region 將json字符串轉化成為一個string的二維數組
/// <summary>
/// 將json字符串轉化成為一個string的二維數組
/// </summary>
/// <param name="strJson">json字符串</param>
/// <param name="num">列</param>
/// <returns>返回結果的二維數組</returns>
public static string[,] JsonToArry(string strJson,int num)
{
string[,] strValue =null;
//轉換json格式
strJson = strJson.Replace(",\"", "*\"").Replace("\":", "\"#").ToString();
//取出表名
var rg = new Regex(@"(?<={)[^:]+(?=:\[)", RegexOptions.IgnoreCase);
string strName = rg.Match(strJson).Value;
//DataTable tb = null;
//去除表名
strJson = strJson.Substring(strJson.IndexOf("[") + 1);
strJson = strJson.Substring(0, strJson.IndexOf("]"));
//獲取數據
rg = new Regex(@"(?<={)[^}]+(?=})");
MatchCollection mc = rg.Matches(strJson);
int n=mc.Count;
strValue=new string[n,num];
for (int i = 0; i < mc.Count; i++)
{
string strRow = mc[i].Value;
string[] strRows = strRow.Split('*');
for (int j = 0; j < strRows.Length; j++)
{
strRows[j] = strRows[j].Replace(",", ",").Replace(":", ":").Replace("\"", "");
strValue[i,j] = strRows[j].Split('#')[1];
}
}
return strValue;
}
#endregion