小编for*_*dsj的帖子

从web api JSON C#中删除斜杠

我有一个WEB API C#,里面我有Data这是一个链接,例如: images/Chinese/AbaloneEggCustard.jpg

但在JSON中,它看起来像这样:

[{"BackgroundImage":"images\/Chinese\/AbaloneEggCustard.jpg", ......}]
Run Code Online (Sandbox Code Playgroud)

我可以知道如何删除斜线?需要删除所以希望我可以访问与azure链接时的图像.


这是我的控制器代码:

public IEnumerable<Food> Get()
    {
        List<Food> Cases = new List<Food>();
        try
        {
            string connectionString = ConfigurationManager.ConnectionStrings["HealthyFoodDBConnectionString"].ConnectionString;
            myConnection = new SqlConnection(connectionString);
            myConnection.Open();

            string sql = "SELECT * from [Recipe] ";

            myCommand = new SqlCommand(sql, myConnection);
            myDataReader = myCommand.ExecuteReader();

            while (myDataReader.Read())
            {
                Cases.Add(new Food()
                {
                    RecipeID = (int)myDataReader["RecipeID"],
                    RecipeTitle = (string)myDataReader["RecipeTitle"],
                    FoodCategoryID = Convert.ToInt32(myDataReader["FoodCategoryId"]),
                    Serves = (string)myDataReader["Serves"],
                    PerServing = (string)myDataReader["PerServing"],
                    Favourite = ((Convert.ToInt32(myDataReader["Favourite"]) == 1) ? true : false),
                    Directions = (string)myDataReader["Directions"],
                    BackgroundImage = …
Run Code Online (Sandbox Code Playgroud)

c# json getjson asp.net-web-api

5
推荐指数
1
解决办法
4591
查看次数

标签 统计

asp.net-web-api ×1

c# ×1

getjson ×1

json ×1