[System.Web.Http.HttpPost]
public HttpResponseMessage GetProduct([FromBody] dynamic json)
{
var product = new { success = true, errorMsg = "", data = "" };
string jsons = Convert.ToString(json);
var products = Post(jsons);//调用接口方法
ResultMsg res = JsonConvert.DeserializeObject<ResultMsg>(products);
bool succ =Convert.ToBoolean( res.success.ToString());
string mes = res.errorMsg.ToString();
string dataa = res.data.ToString();
if (succ==true)
{
product = new { success = true, errorMsg = mes,data=dataa};
}
else
{
product = new { success = false, errorMsg = mes, data = dataa };
}
HttpResponseMessage result = new HttpResponseMessage();
result.Content = new StringContent(JsonConvert.SerializeObject(product), Encoding.GetEncoding("UTF-8"), "application/json");
return result;
}
大概逻辑是调用这个方法,在此方法中在调用真正的接口方法,将返回值给设定一下格式基本就可以了。最基本的方法。
|