我有一个调用另一个.netcore api(remoteApi)的web (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\\\":\\\"\\\" } } }\""我怎么才能避免这个问题呢?
https://stackoverflow.com/questions/41556777
复制相似问题