WEB API JSON序列化循环引用

时间:2015-06-11 01:01:47

标签: json.net entity-framework-6 asp.net-web-api2

我正在尝试从Web API接收的子实体访问属性字段(JSON)。但是,通过查看浏览器控制台,它显示的是引用而不是字段。如何访问这些字段?

ANGULAR JS VIEW

> all.var
class       : RasterBrick 
dimensions  : 89, 180, 16020, 34  (nrow, ncol, ncell, nlayers)
resolution  : 2, 2  (x, y)
extent      : -179, 181, -89, 89  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
data source : in memory
names       :    period_max, pct_signif_periodmax, pct_coi_periodmax,    pct_ispos_signif, events_pos_periodmax, events_neg_periodmax, events_pos_all, events_neg_all,  maxpower_pos,  maxpower_neg, maxpower_events_pos, maxpower_events_neg, maxpower_pos_norm, maxpower_neg_norm, maxpower_events_pos_norm, ... 

> point
Lon      Lat
1  166.2790 -10.2690
2   26.9000 -33.6000
3  153.6209 -28.7001
4  113.8333 -28.6833
5  153.6335 -28.6591
6  153.5836 -28.4643
7   32.6833 -27.5333
8   32.6880 -27.5260
9   32.6880 -27.5260
10  32.6880 -27.5260


> point.extract<-extract(all.var, point, buffer=50000,na.rm=TRUE,fun=mean)
Error in apply(x, 2, fun2) : dim(X) must have a positive length

服务

 <table infinite-scroll='tF.loadMore()' infinite-scroll-disabled='tF.isBusy' infinite-scroll-distance='3' class="responsive">
            <thead>
                <tr>
                    <th>FIELD 1</th>
                    <th>FIELD 2</th>
                    <th>FIELD 3</th>
                    <th>FIELD 4</th>
                    <th>FIELD 5</th>
                </tr>
            </thead>
            <tbody>
                <tr ng-repeat="item in tF.items | filter:searchFilter">
                    <td>{{item.CompanyDomainModel.CompanyName}}</td>
                    <td>{{item.RatingDomainModel.RatingValue}}</td>
                    <td>{{item.Views}}</td>
                    <td>{{item.Clicks}}</td>
                    <td>{{item.EmailSent}}</td>
                </tr>
            </tbody>
            <tfoot ng-show='tF.isBusy'>
                <tr>
                    <td colspan="9"><spinner show="tF.isBusy" /><span class="bold">{{tF.status}}</span> </td>
                </tr>
            </tfoot>
        </table>

ENDPOINT

public ICollection<CompanyStatDomainModel> GetRecordsByPageSize(int page) { 
  const int pgeSize = 20; 
  var result = _companyStatRepo
    .AllIncluding(c => c.CompanyDomainModel, c => c.RatingDomainModel) 
    .OrderBy(c => c.CompanyStatId)
    .Skip(page * pgeSize)
    .Take(pgeSize)
    .ToList(); 
  return result; 
} 

评分域名模型

IHttpActionResult GetRecordsByPageSize(int page) { 
  var companyStatService = new CompanyStatService(); 
  return Ok(companyStatService.GetRecordsByPageSize(page)); 
} 

输出

Please see below URL to see the results I am getting from the API

1 个答案:

答案 0 :(得分:20)

将以下代码添加到WebApiConfig.cs

ShadowUploader