返回Json和返回XML的Object格式⭐⭐⭐⭐⭐

 var obj = new JObject
                {
                    {"Head", new JObject
                        {
                            { "key","" },
                            { "key",transCode },
                            { "key", transId },
                            { "key", "" }
                        }
                    },
                    {"Body", new JObject
                        {
                            { "CreateDateTime", _datetime.Now.DateTime }
                        }
                    }
                };
                result = new ContentResult()
                {
                    Content = Newtonsoft.Json.JsonConvert.SerializeObject(obj),
                    ContentType = "application/json"
                };
                XDocument obj = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
               
                XElement root = new XElement("response",
                                    new XElement("key", "success"),
                                    new XElement("key", ""),
                                    new XElement("key", ""));

                obj.Add(root);

                result = new ContentResult()
                {
                    Content = obj.ToString(),
                    ContentType = "application/xml"
                };

 

posted @ 2020-04-17 13:12  ProZkb  阅读(208)  评论(0编辑  收藏  举报