[英]How can I get rid of double \ character (\\) which I keep in database
我在MsSql數據庫中有一些數據,並通過Csharp Web Apis將它們發送到我的Android應用程序。 nvarchar字段中有一些unicode字符。 字符串數據中間有。 例如:'F \\ u2081大於F \\ u2082'
數據繼續流向移動應用程序,因為“F \\ u2081大於F \\ u2082”。 因此,unicode字符永遠不會成功顯示。
我搜索並嘗試了很多方法但到目前為止沒有成功。 您可以測試並查看web api的結果(帖子) http://www.kelimex.com.tr/teogapi/api/Fen
在結果視圖中,“message”字段數據來自數據庫。 但是我在web api的源代碼中輸入了“解釋”字段數據。
正如您將看到“解釋”字段中沒有問題。 但“消息”字段不斷顯示錯誤。
有沒有人在這個問題上有任何經驗?
這是csharp代碼,它從Sql中提取數據並返回web api的列表。 目前還沒有編碼解碼等......無論如何都沒有。
public List<Result> test()
{
List<Result> list = new List<Result>();
if (ConnectToDB())
{
try
{
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("__tm_test", conn);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.Fill(ds, "ds");
if (ds.Tables.Count > 0)
{
Result item = new Result();
item.statusCode = 1;
item.status = true;
item.message = ds.Tables[0].Rows[0]["FieldNVarchar"].ToString();
item.explanation = "F\u2081 is greater than F\u2082";
list.Add(item);
}
ds.Dispose();
da.Dispose();
}
catch (Exception e)
{
}
}
return list;
}
You should use HttpUtility.UrlEncodeUnicode and HttpUtility.UrlEncode for text you are setting a variable. Please check the below example:
//Encode a text
var myText = HttpUtility.UrlEncodeUnicode(MyText)
//And Decode text you are getting
var MyTextNew = HttpUtility.UrlEncode(text)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.