• web api(基于NFine框架) 中接口跳转数据格式错误解决方案


    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("
    ", "");
                    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再转成要返回的对象类型,再返回,这样就不会出错了。
  • 相关阅读:
    关于雷达(Radar)信道
    关于High CPU及基本排查
    UCS内存问题排查
    ASA-ACL类型
    思科室外AP无法注册到WLC
    WLC-Right to Use Licensing
    无线连接网络-FAST SSID Change
    ASA升级
    ASA密码恢复流程
    Mobility Express部署外部镜像服务器
  • 原文地址:https://www.cnblogs.com/jbdxbl/p/9590235.html
Copyright © 2020-2023  润新知