[英]Return named JSON object from c# service in .NET
I have a wcf service in .net, which i want to return a named JSON object. 我在.net中有一个wcf服务,我想返回一个命名的JSON对象。 This is how i want to return the JSON object:
这就是我要返回JSON对象的方式:
{"file":"\/9j\/4AAQSkZJRgABAQEASABIAAD\/4"}
But this is how it is returned from the service in c# 但这是从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));
}
Create an object with that string as a property. 使用该字符串作为属性创建一个对象。 This should work:
这应该工作:
return JsonConvert.SerializeObject(
new { file = System.Convert.ToBase64String(image) }
);
You have to create an new object. 您必须创建一个新对象。
var file = JsonConvert.SerializeObject(System.Convert.ToBase64String(image));
return Json(new {file},JsonRequstBehavior.AllowGet);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.