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));
    }

2 Answers 2

1

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

return JsonConvert.SerializeObject(
  new { file = System.Convert.ToBase64String(image) }
);
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks!, almost. However it returns this "{\"file\":\"\/9}" and i want to return this {"file":"\/9}. Maybe i have to correct this in php?
I fixed this problem by returning a stream instead. According to this post: stackoverflow.com/questions/3078397/…
0

You have to create an new object.

var file = JsonConvert.SerializeObject(System.Convert.ToBase64String(image));
return Json(new {file},JsonRequstBehavior.AllowGet);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.