Outputs json and mvcjson for the ASP. net mvc view.
Make a small exercise and output a json string for the asp.net mvc view:
Create a JsonResult:
Create this view:
Browsing result:
In MVC3, how does one output Json data when the page is opened, how does one pop up the Json Data box, the specific code, the test passes the plus points, no difference
What data basket do you want to play with alert?
How to parse json in aspnet mvc
Public static DataTable JsonToDataTable (string strJson)
{
// Retrieve the table name
Regex rg = new Regex (@"(? <= {) [^:] + (? =: \ [) ", RegexOptions. IgnoreCase );
String strName = rg. Match (strJson). Value;
DataTable tb = null;
// Remove the table name
StrJson = strJson. Substring (strJson. IndexOf ("[") + 1 );
StrJson = strJson. Substring (0, strJson. IndexOf ("]");
// Obtain data
Rg = new Regex (@"(? <= {) [^}] + (? = })");
MatchCollection mc = rg. Matches (strJson );
For (int I = 0; I <mc. Count; I ++)
{
String strRow = mc [I]. Value;
String [] strRows = strRow. Split (',');
// Create a table
If (tb = null)
{
Tb = new DataTable ();
Tb. TableName = strName;
Foreach (string str in strRows)
{
DataColumn dc = new DataColumn ();
String [] strCell = str. Split (':');
Dc. ColumnName = strCell [0]. ToString ();
Tb. Columns. Add (dc );
}
Tb. AcceptChanges ();
}
// Add content
DataRow dr = tb. NewRow ();
For (int r = 0; r <strRows. Length; r ++)
{
... The remaining full text>