无法导航对象结构并提取json结果的内容

时间:2015-12-15 12:04:59

标签: c# json

我正在尝试使用API​​调用来填充包含数据库中数据的列表框。我无法从结果中提取数据。

API调用代码:

[Route("api/GetStateOrProvinceListing")]
[HttpGet]
[ResponseType(typeof(List<StateOrProvince>))]
public IHttpActionResult GetStateOrProvinceListing()
{
    BusinessLogicLayer_Generic _oBusinessLogicLayer_Generic = new BusinessLogicLayer_Generic();
    return Ok(_oBusinessLogicLayer_Generic.GetStateOrProvince().ToList());
}

我在Chrome控制台中解压缩后得到的结果:

  

[对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象]

当我展开其中一个对象时,我得到以下内容:

Abbreviation: "OK"
CountryOrRegionID: "3e45df44-319a-412f-902e-0b4b6c5bc5ad"
CreatedByID: "cea50dbc-1204-4e7f-9053-9b81f8a75add"
CreatedDateTime: "2015-02-03T00:55:51.353"
DisabledByID: null
DisabledDateTime: null
Enabled: true
ID: "d8088ea4-2a9b-46a6-8c4c-08a187dff2f8"
ModifiedByID: null
ModifiedDateTime: null
Name: "Oklahoma"
__proto__: Object

应该填充我的列表的HTML:

function populateStateFields() {
    callService("GET", g_WebServiceGetStateOrProvinceListingURL, null, function (jsonResult) {
        debugger;
        $(jsonResult).each(function () {
            $("<option />", {
                val: this.StateOrProvinceID,
                text: this.StateOrProvinceAbbreviation
            }).appendTo(listContactInformationStateAbbreviation);

            $("<option />", {
                val: this.StateOrProvinceID,
                text: this.StateOrProvinceAbbreviation
            }).appendTo(listLegalInformationStateAbbreviation);
        });
    });
}

最后,AJAX Call:

function callService(Type, Url, Data, successFunction) {
    $.ajax({
        type: Type,                     // GET or POST or PUT or DELETE verb
        url: Url,                       // Location of the service
        data: Data,                     // Data sent to server
        dataType: "json",
        success: successFunction,
        error: serviceErrorHandler      // When Service call fails
    });
}

结果是75个空白条目的列表。我需要做些什么来解析&#34;解析&#34;或浏览我的列表?

0 个答案:

没有答案