私はこの契約があります。WCF Rest Webサービス(弱く型付けされたJson)レスポンスに対して、私のJson文字列レスポンスがエスケープされるのはなぜですか?
[ServiceContract]
public interface IServiceJsonContract
{
[WebInvoke(UriTemplate = "/MyMethod", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, Method = "POST")]
Message MyMethod(Message input);
}
そしてMyMethodはのために定義されています:
"{\" BLA \ ":
Message MyMethod(Message input)
{
...
Message response = Message.CreateMessage(
MessageVersion.None,
"*",
"{\"bla\": 2 }",
new DataContractJsonSerializer(typeof(string)));
response.Properties.Add(WebBodyFormatMessageProperty.Name,new
WebBodyFormatMessageProperty(WebContentFormat.Json));
var contextOutgoingResponse = WebOperationContext.Current.OutgoingResponse;
contextOutgoingResponse.ContentType = "application/json;charset=utf-8";
return response;
}
私はJSONエスケープましメソッドを呼び出す場合: 2}」
エスケープされていないもの(以下):
"{" bla ":2}"
エスケープされていないJson( "{" bla ":2}")の入手方法はありますか?
おかげ
独自のJSONを作成する代わりに、辞書またはオブジェクトを渡す必要があります。 – SLaks
ありがとう、SLaks。私の場合は文字列があり、DataContractJsonSerializerも文字列ですが、これはレスポンスをエスケープします – Cezar