我遇到了一个问题,使用HttpResponseMessage
获取多个Json对象。如何做到不将字符串包装为Json?
目前我尝试的代码如下...
private HttpResponseMessage SetToJson(string jsonString)
{
string str = "ABC";
HttpRequestMessage Request = new HttpRequestMessage();
Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());
Request.Content = new StringContent(jsonString, Encoding.UTF8, "application/json");
return Request.CreateResponse(HttpStatusCode.OK, new { jsonString, str }, JsonMediaTypeFormatter.DefaultMediaType);
}
功能正常,但它自己附加了\r\n"。如何修复?还有其他替代方案吗?
这是以上代码返回的响应。
{"jsonString":["{\r\n \"resourceType\": \"Patient\",\r\n \"entry\": []\r\n}","ABC"]}