我已经使用 C# 和 MySQL 在 asp.net 中创建了 webservice。我想从此服务返回多个值。我正在使用以下代码:
[WebMethod]
public string RegisterUserViaFacebook(string fbid, string fbmailid,string devicetype)
{
string success = "Already Registered";
string id="", name="";
if (!ExistsFBID(fbid))
{
name = GenerateUserName();
string password = generatePassword(10);
string insertUser = "Insert into tbl_userinfo(UserName,Password,Facebook_ID,Facebook_EmailID,DeviceType) values";
insertUser += "( '" + name + "' ,'" + password + "','" + fbid + "','" + fbmailid + "','" + devicetype + "' )";
con = new MySqlConnection(conString);
con.Open();
MySqlCommand cmd = new MySqlCommand(insertUser, con);
success = cmd.ExecuteNonQuery().ToString();
con.Close();
string getID = "SELECT UserID from tbl_userinfo where UserName='" + name + "' ";
con = new MySqlConnection(conString);
con.Open();
MySqlCommand cmd1 = new MySqlCommand(getID, con);
id = cmd1.ExecuteScalar().ToString();
con.Close();
if (Convert.ToInt16(success) > 0)
{
SendMail(fbmailid, name, password);
success = "New User" ;
}
else
success = "Error in Insertion";
}
else
{
string getID1 = "SELECT UserID, UserName from tbl_userinfo where Facebook_ID='" + fbid + "' ";
con = new MySqlConnection(conString);
con.Open();
MySqlCommand cmd2 = new MySqlCommand(getID1, con);
MySqlDataReader info = cmd2.ExecuteReader();
while (info.Read())
{
id = info.GetString(0);
name = info.GetString(1);
}
con.Close();
}
string jsonString = JsonConvert.SerializeObject(success);
String finalString = "{\"USER IS\":";
finalString += jsonString;
finalString += "}";
string jsonString1 = JsonConvert.SerializeObject(id);
String finalString1 =finalString + "{\"ID IS\":";
finalString1 += jsonString1;
finalString1 += "}" ;
string jsonString2 = JsonConvert.SerializeObject(name);
String finalString2 = finalString1 + "{\"NAME IS\":";
finalString2 += jsonString2;
finalString2 += "}";
return finalString2;
}
但它返回单个字符串中的所有值。我想将值单独返回为Succeess
,ID
和Name
.
我怎样才能做到这一点?