using NFine.Code;
using NFine.Domain;
using System.Web.Http;
using Newtonsoft.Json;
namespace Api.Controllers.bp
{
public class School_VersionController : BaseController
{
// GET: School_Version
//3.3检测是否有新的版本信息
[System.Web.Http.HttpPost]
public IHttpActionResult checkVersion([FromBody]param param)
{
IInterFaceEntity iinter = new IInterFaceEntity();
WebHelper webhelp = new WebHelper();
string Url = "http://localhost:8082/Api/School_Version/checkVersion";
bool isPost = true;
try
{
string parament = "F_currentVersion=" + param.F_currentVersion + "";
string getversion = webhelp.HttpWebRequest(Url, parament, isPost).Replace("\r\n", "");
return Json(JsonConvert.DeserializeObject(getversion, iinter.GetType()));
}
catch (System.Exception ex)
{
iinter.IsError = true;
iinter.ErrorCodeValue = "0001";
iinter.ErrorMsgInfo = ex.Message;
iinter.Body = "";
return Json(iinter);
}
}
}
public class param
{
public string F_currentVersion { get; set; }//版本号
}
}
问题:当接口1调用接口2时,接口2返回的时一个对象,而接口1中接受并解析完后,会存入一个字符串中,该字符串格式并不能符合json的格式要求,因此会出错。
主要的一步:
return Json(JsonConvert.DeserializeObject(getversion, iinter.GetType()));
将字符串getversion再转成要返回的对象类型,再返回,这样就不会出错了。
