zoukankan      html  css  js  c++  java
  • 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再转成要返回的对象类型,再返回,这样就不会出错了。
  • 相关阅读:
    GC原理---垃圾收集算法
    GC原理---对象可达判断
    散列算法和哈希表结构
    桶排序
    Spring事务梳理
    AQS
    重入锁
    CAS
    研究一下phpspider
    用php写爬虫去爬数据
  • 原文地址:https://www.cnblogs.com/jbdxbl/p/9590235.html
Copyright © 2011-2022 走看看