zoukankan      html  css  js  c++  java
  • web api返回格式小结

    web api返回格式小结:

    1.默认是返回xml格式数据,如果需要返回json格式,需要在Global.asax中加入:

    GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();

    2.当以string数据类型返回时,默认是加双引号,如果需要将双引号去掉,需要将string类型转换并以HttpResponseMessage类型返回,

    string result = "***";

    HttpResponseMessage result_return = new HttpResponseMessage();

    result_return = new HttpResponseMessage { Content = new StringContent(result, Encoding.GetEncoding("UTF-8"), "text/plain") };

    以json格式返回:

    Result_return = new HttpResponseMessage { Content = new StringContent(result, Encoding.GetEncoding("UTF-8"), "application/json") };

  • 相关阅读:
    Mysql 数据库高级
    Mysql 数据库
    并发编程
    网络编程
    1113
    1112
    P相遇游戏
    中位数
    PETS
    打暴力程序的正确做法
  • 原文地址:https://www.cnblogs.com/zhangtingzu/p/5945829.html
Copyright © 2011-2022 走看看