后台JSON数据生成
using System.Web.Services;//要应用这个空间
[WebMethod]
public static string Textjson()
{
string sql = "SELECT simid,country,days,simcontent,simprice from simshop";
DataTable dtsim = SqlHelper.ExecuteQuery(sql);
string data= ToJson(dtsim);
return data;
}
Datatable转换为Json
public static string ToJson(DataTable dt)
{
StringBuilder jsonString = new StringBuilder();
jsonString.Append("[");
DataRowCollection drc = dt.Rows;
for (int i = 0; i < drc.Count; i++)
{
jsonString.Append("{");
for (int j = 0; j < dt.Columns.Count; j++)
{