本文整理汇总了C#中System.Web.Script.Serialization.JavaScriptSerializer.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Script.Serialization.JavaScriptSerializer.ToString方法的具体用法?C# Script.Serialization.JavaScriptSerializer.ToString怎么用?C# Script.Serialization.JavaScriptSerializer.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Script.Serialization.JavaScriptSerializer
的用法示例。
在下文中一共展示了Script.Serialization.JavaScriptSerializer.ToString方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckAvailability
public string CheckAvailability(string userName)
{
try
{
using (SqlConnection sqlDBConnection = new SqlConnection(ConnectionString))
{
StringBuilder sqlstmt = new StringBuilder("select EmployeeID, EmployeeName from [dbo].[EmployeeDB] where EmployeeName = @userName COLLATE Latin1_General_CS_AS ");
//sqlstmt.Append(Convert.ToString(userid));
SqlCommand myCommand = new SqlCommand(sqlstmt.ToString(), sqlDBConnection);
myCommand.CommandType = CommandType.Text;
myCommand.Parameters.AddWithValue("@userName", userName);
bool foundRecord = false;
sqlDBConnection.Open();
using (SqlDataReader myReader = myCommand.ExecuteReader())
{
if (myReader.Read())
foundRecord = true;
myReader.Close();
}
sqlDBConnection.Close();
object jsonObject = new { available = (!foundRecord) };
var json = new JavaScriptSerializer().Serialize(jsonObject);
return json.ToString();
}
}
catch (Exception ex)
{
return string.Format("Exception : {0}", ex.Message);
}
}
示例2: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
Autentificador recibido = new JavaScriptSerializer().Deserialize<Autentificador>(Request.Params["datos"]);
Response.Write(recibido.ToString());
Response.ContentType = "application/json";
Response.End();
}
示例3: CheckAvailability
public string CheckAvailability(string userName)
{
try
{
using (SqlConnection sqlDBConnection = new SqlConnection(ConnectionString))
{
StringBuilder sqlstmt = new StringBuilder("select id,username,password,firstname,lastname,address,contactnumber,dateofbirth,emailid,securityquestion,answer,addressproof,photoidentity,status,rewardpoints from [dbo].[User] where username = @userName COLLATE Latin1_General_CS_AS ");
SqlCommand myCommand = new SqlCommand(sqlstmt.ToString(), sqlDBConnection);
myCommand.CommandType = CommandType.Text;
myCommand.Parameters.AddWithValue("@userName", userName);
bool foundRecord = false;
sqlDBConnection.Open();
using (SqlDataReader myReader = myCommand.ExecuteReader())
{
if (myReader.Read())
foundRecord = true;
myReader.Close();
}
sqlDBConnection.Close();
object jsonObject = new { available = (!foundRecord)};
var json = new JavaScriptSerializer().Serialize(jsonObject);
return json.ToString();
}
}
catch (Exception ex)
{
return string.Format("Exception : {0}", ex.Message);
}
}
示例4: CheckAvailability
public string CheckAvailability(string userName)
{
try
{
using (SqlConnection sqlDBConnection = new SqlConnection(ConnectionString))
{
StringBuilder sqlstmt = new StringBuilder("SELECT COUNT(*) FROM Customer WHERE [email protected]");
//sqlstmt.Append(Convert.ToString(userid));
SqlCommand myCommand = new SqlCommand(sqlstmt.ToString(), sqlDBConnection);
myCommand.CommandType = CommandType.Text;
myCommand.Parameters.AddWithValue("@userName", userName);
bool foundRecord = false;
sqlDBConnection.Open();
int val = (int)myCommand.ExecuteScalar();
if (val >0)
foundRecord = true;
sqlDBConnection.Close();
object jsonObject = new { available = (!foundRecord) };
var json = new JavaScriptSerializer().Serialize(jsonObject);
return json.ToString();
}
}
catch (Exception ex)
{
return string.Format("Exception : {0}", ex.Message);
}
}
示例5: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
// Creating Instance(object) of employee class
Employee empObj = new Employee();
// Assinging values to employee object
empObj.FirstName = "Kannadasan";
empObj.LastName = "Govindasamy";
empObj.Designation = "Tech Lead"; ;
empObj.Department = "Development";
empObj.DOB.Date = 30;
empObj.DOB.Month = 4;
empObj.DOB.Year = 1988;
// Serialize Employee Object
var json = new JavaScriptSerializer().Serialize(empObj);
Response.Write(json.ToString());
}
开发者ID:dotnetpickles,项目名称:Serialization-Deserializaton-In-ASP.Net-C-.Net,代码行数:18,代码来源:Serialization.aspx.cs
示例6: CheckAvailability
public string CheckAvailability(string userName)
{
try
{
string connectionString = ConfigurationManager.ConnectionStrings["databaseConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(connectionString);
con.Open();
SqlCommand command = new SqlCommand("select count(*) from dbo.Users where username='" + userName + "';", con);
SqlDataReader reader = command.ExecuteReader();
reader.Read();
bool isUserNameAvailable = (Convert.ToInt32(reader[0]) == 0 );
object jsonObject = new { available = isUserNameAvailable };
var json = new JavaScriptSerializer().Serialize(jsonObject);
return json.ToString();
}
catch (Exception ex)
{
return string.Format("Exception : {0}", ex.Message);
}
}
示例7: LogError
public void LogError(long order_id,string err_subject, string err_msg,oCreateOrderRequest o, string ip)
{
try
{
email em = new email();
em.SendEmail("[email protected]", "[email protected]", "", "[email protected]", "RedBubble endpoint", err_subject, err_msg, "smtp.yourself.com", "", "", "", false);
using (var dc = new redbubbleDataContext())
{
dc.sp_insert_orders_error_log(order_id, err_subject, err_msg, ip);
}
}
catch { }
try
{
var json = new JavaScriptSerializer().Serialize(o);
using (var dc2 = new redbubbleDataContext())
{
dc2.sp_update_ordrers_err_log_json(order_id, json.ToString());
}
}
catch { }
}
示例8: SaveUserPreferences
private HttpResponseMessage SaveUserPreferences(UserPreference preferences, string user)
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(ConfigurationManager.AppSettings["APIurl"] + "/api/UserPreference/SaveUserPreference");
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var json = new JavaScriptSerializer().Serialize(preferences);
string urlParameters = "?user=" + user + "&preferences=" + json.ToString();
HttpContent content = new StringContent("");
HttpResponseMessage response = client.PostAsync(urlParameters, content).Result;
return response;
}
示例9: SerializeObject
public String SerializeObject(Object obj)
{
var json = new JavaScriptSerializer().Serialize(obj);
return json.ToString();
}
示例10: LogOn
public ActionResult LogOn(LogOnModel model, string returnUrl)
{
if (ModelState.IsValid)
{
var json = new JavaScriptSerializer().Serialize(model);
//if (Membership.ValidateUser(model.Email, model.Password))
if(Http.HttpPost("http://localhost:8080/Auth/Validate", json.ToString()).Equals("\"ok\""))
{
return RedirectToAction("Index", "Home");
//FormsAuthentication.SetAuthCookie(model.Email, model.RememberMe);
//if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
// && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
//{
// return Redirect(returnUrl);
//}
//else
//{
// return RedirectToAction("Index", "Home");
//}
}
else
{
ModelState.AddModelError("", "The user name or password provided is incorrect.");
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
示例11: Register
public ActionResult Register(RegisterModel model)
{
if (ModelState.IsValid)
{
// Attempt to register the user
//MembershipCreateStatus createStatus;
var json = new JavaScriptSerializer().Serialize(model);
//Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus);
//int createStatus = System.Convert.ToInt32(Http.HttpPost("http://localhost:8080/Auth", "{\"Email\":\"2147483647\",\"Password\":\"String content\"}"));
int createStatus = System.Convert.ToInt32(Http.HttpPost("http://localhost:8080/Auth/Register", json.ToString()));
if (createStatus == 0)
{
//FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);
return RedirectToAction("Index", "Home");
}else if(createStatus == 7)
{
ModelState.AddModelError("", ErrorCodeToString(MembershipCreateStatus.DuplicateEmail));
}
else
{
ModelState.AddModelError("", ErrorCodeToString(new MembershipCreateStatus()));
}
}
// If we got this far, something failed, redisplay form
return View(model);
}