0

I have a wcf service in .net, which i want to return a named JSON object. This is how i want to return the JSON object:

{"file":"\/9j\/4AAQSkZJRgABAQEASABIAAD\/4"}

But this is how it is returned from the service in c#

"\"\/9j\/4AAQSkZJRgABAQEASABIAAD\/4

This is the code i use to return it

[WebInvoke(Method = "GET",
                ResponseFormat = WebMessageFormat.Json,
                UriTemplate = "getFile/{fname}")]
    public string GetFile(string name)
    {
        /*
         * Some code (not important)
         */

        return JsonConvert.SerializeObject(System.Convert.ToBase64String(image));
    }
4

2 に答える 2

1

Create an object with that string as a property. This should work:

return JsonConvert.SerializeObject(
  new { file = System.Convert.ToBase64String(image) }
);
于 2012-09-14T08:33:43.023 に答える
0

新しいオブジェクトを作成する必要があります。

var file = JsonConvert.SerializeObject(System.Convert.ToBase64String(image));
return Json(new {file},JsonRequstBehavior.AllowGet);
于 2012-09-14T08:34:33.720 に答える