【发布时间】:2017-05-24 05:32:51
【问题描述】:
我有一个调用另一个 web api(remoteApi) 的 .netcore web api(localApi)。 remoteApi 返回 json,我的目标是向该 json 添加一个新属性并将其作为 json 返回给调用 localApi 的调用者。
到目前为止,我的代码是这样的:
var httpResponse = await httpClient.PostAsync(remoteApi), httpContent);
// If the response contains content we want to read it!
if (httpResponse.Content != null)
{
responseContent = await httpResponse.Content.ReadAsStringAsync();
responseContent = responseContent.Insert(2, " \"isCachedResponse\": false,");
var retVal = await Task.Run(() => JsonConvert.SerializeObject(responseContent));
return Ok(retVal);
}
这种方法的问题是响应是字符串而不是 json。 如下:
"\"{ \"isCachedResponse\": true, \\\"remoteApiResponse\\\":{ \\\"applicationId\\\":\\\"10001000000300071\\\", \\\"reasons\\\":[ { \\\"reason\\\":\\\"Score Cut Policy\\\" } ], \\\"decisionText\\\":\\\"Duplicate request; check UI for more information\\\", \\\"decisionCode\\\":\\\"Undecisioned\\\", \\\"officialNameOnFile\\\":{ \\\"firstName\\\":\\\"\\\", \\\"middleName\\\":\\\"\\\", \\\"lastName\\\":\\\"\\\" } } }\""
我怎样才能解决这个问题?
【问题讨论】:
标签: c# asp.net-mvc asp.net-web-api asp.net-core-webapi