///& lt; Summary>
///Json string into a DataTable data collection
///& lt;/summary>
///& lt; Param name="json" & gt;
///& lt; Returns>
Public static DataTable DtToJson (string json)
{
////remove the table name
//Regex rg=new Regex (@ "? <[^ :] + (={)?=:/[) ", RegexOptions IgnoreCase);
//string strName=rg. Match (strJson). The Value;
The DataTable TB=null;
////remove the table name
//strJson=strJson Substring (strJson IndexOf (" ") + 1);
//strJson=strJson. Substring (0, strJson IndexOf ("] "));
//get data
The Regex rg=new Regex (@ "? <[^}] + (={)?=}) ");
MatchCollection MC=rg. Matches (json);
for (int i=0; I & lt; MC. Count; I++)
{
String strRow=MC [I] Value;
String [] strRows=strRow. Split (', ');
//create a table
If (TB==null)
{
TB=new DataTable ();
TB. TableName="";
The foreach (string STR in strRows)
{
DataColumn dc new DataColumn ();
String [] strCell=STR. The Split (', ');
Dc. ColumnName=strCell [0]. ToString (). The Replace (" \ ""," "). The Trim ();
TB. The Columns. The Add (dc);
}
TB. The AcceptChanges ();
}
//add content
DataRow Dr=TB. NewRow ();
For (int r=0; R & lt; StrRows. Length; R++)
{
Dr=strRows [r] [r]. The Split (' : ') [1]. The Trim (). The Replace (", ", ", ""). The Replace (" :", ":"). The Replace ("/", ""). The Replace (" " ", ""). The Trim ();
}
TB. Rows. The Add (Dr);
TB. The AcceptChanges ();
}
Return the TB;
}
Json string format is as follows:
Goal: by modifying the above function after a json string into a datatable, you can take to process_code value, how to do?
CodePudding user response:
BBS is the main principle of learning and skills, not free to do my homework or help to work,