从JSON中排除Odata元数据和类型

时间:2015-03-06 22:21:19

标签: json asp.net-web-api odata

下面的脚本从我的ODataController返回一个JSON

< script >
  $(document).ready(function() {
    $.ajax({
      url: "http://localhost:37994/odata/EPStructures3/",
      type: "Get",
      contentType: 'application/json; charset=utf-8',
      success: function(data) 
      {
        //do something.....
      },
      error: function(msg)
      {
        alert(msg);
      }
    });
  }); 
< /script>

JSON:

{ "odata.metadata":"http://localhost:37994/odata/$metadata#EPStructures3","value":[{"eps_level":0,"id":2},{"eps_level":1,"id":3}]}

我想排除元数据和类型,以便像这样返回JSON:

[{"eps_level":0,"id":2},{"eps_level":1,"id":3}]

我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:3)

如果您在请求中添加“Accept:application / json; odata.metadata = none”标题,您将尽可能接近您想要的内容。