我已经制作了一个web服务和一些web方法,我在我的android应用程序中调用ksoap工作。 其中一个方法获取一个Farsi字符串并将其插入数据库,但当我退出并检查时,我只看到问号(?)而不是波斯语字符。
使用ksoap在我的Android应用程序中使用Web服务调用方法
public String sendcomment(String Comment , Float rate)
{
String MethodName="SetResComment";
try {
SOAP_ACTION = namespace + MethodName;
//Adding values to request object
request = new SoapObject(namespace, MethodName);
//Adding string value to request object
PropertyInfo P_RSID =new PropertyInfo();
P_RSID.setName("RSID");
P_RSID.setValue(staticvar.CurrentRes.getID()); //llllllllll
P_RSID.setType(String.class);
request.addProperty(P_RSID);
PropertyInfo P_UID =new PropertyInfo();
P_UID.setName("UID");
P_UID.setValue(staticvar.UID); //llllllllll
P_UID.setType(String.class);
request.addProperty(P_UID);
PropertyInfo P_Name =new PropertyInfo();
P_Name.setName("Name");
P_Name.setValue(staticvar.Mame); //llllllllll
P_Name.setType(String.class);
request.addProperty(P_Name);
PropertyInfo P_Comment =new PropertyInfo();
P_Comment.setName("Comment");
P_Comment.setValue(Comment); //llllllllll
P_Comment.setType(String.class);
request.addProperty(P_Comment);
PropertyInfo P_Rate =new PropertyInfo();
P_Rate.setName("Rate");
P_Rate.setValue(String.valueOf(rate)); //llllllllll
P_Rate.setType(String.class);
request.addProperty(P_Rate);
SetEnvelope();
try {
//SOAP calling webservice
androidHttpTransport.call(SOAP_ACTION, envelope);
//Got Webservice response
String result = envelope.getResponse().toString();
return result;
} catch (Exception e) {
// TODO: handle exception
return e.toString();
}
} catch (Exception e) {
// TODO: handle exception
return e.toString();
}
}
我的网络方法:
[WebMethod]
public string SetResComment(string RSID, string UID, string Name, string Comment, string Rate)
{
float rt = float.Parse(Rate);
PayamDB pdb = new PayamDB();
return pdb.SetResComment(RSID, UID, Name, Comment, rt);
}
payamDB类中的setrescomment方法
public string SetResComment(string RSID,string UID, string Name, string Comment,float Rate)
{
try
{
SqlCommand command;
{
command = new SqlCommand("insert into DB_9B1504_daghfood.dbo.T_Res_Comment (ResID,UserID,UserName,Comment,rate,TimeDate) values ('" + RSID + "','" + UID + "','" + Name + "' , '" + Comment + "' , '" + Rate + "' , ' " + System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "')", connection);
command.Connection.Open();
int s=command.ExecuteNonQuery();
command.Connection.Close();
return s.ToString();
}
}
catch (Exception e) { return "error:"+e.Message; }
}
答案 0 :(得分:0)
要在Windows计算机上查看,请下载Farsi字体。 Android也是如此。您是一个问号,因为您的系统不知道什么类型的语言或字体。
答案 1 :(得分:0)
最后我找到了答案
我们应该在插入查询
中使用UTF-8编码的值之前使用N
像这样:
command = new SqlCommand("insert into DB_9B1504_daghfood.dbo.T_Res_Comment (ResID,UserID,UserName,Comment,rate,TimeDate) values ('" + RSID + "','" + UID + "', N'" + Name + "' , N'" + Comment + "' , '" + Rate + "' , ' " + System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "')", connection);