目前,您的网络方法与
String一起返回
ResponseFormat =WebMessageFormat.Json。它遵循字符串的JSON编码。对应于www.json.org,字符串中的所有双引号将使用反斜杠转义。因此,您目前有双重JSON编码。
返回任何类型数据的最简单方法是将
GetCurrentCart()Web方法的输出类型更改为
Stream或
Message(从
System.ServiceModel.Channels)更改为
String。
见http://blogs.msdn.com/b/carlosfigueira/archive/2008/04/17/wcf-raw-
programming-model-
web.aspx,http://msdn.microsoft.com/en-us/library
/ms789010.aspx和http://msdn.microsoft.com/zh-
cn/library/cc681221(VS.90).aspx,以获取代码示例。
因为您没有在问题中写下使用的是哪个.NET版本,所以建议您使用通用且最简单的方法:
public Stream GetCurrentCart(){ //Code ommited var j = new { Content = response.Content, Display=response.Display, SubTotal=response.SubTotal}; var s = new JavascriptSerializer(); string jsonClient = s.Serialize(j); WebOperationContext.Current.OutgoingResponse.ContentType = "application/json; charset=utf-8"; return new MemoryStream(Encoding.UTF8.GetBytes(jsonClient));}


