1

Jquery Ui オートコンプリートを使用しています。

私が抱えている問題は、API から返されるデータです。

"{"d":{"results":[],"facets":{"facet_counts":{"Town":{"":0,"londonderry":136914,"london bridge":1,"london":8983316,"london colney":1}}},"__solr_time":3473457,"__ser_time":1564,"__t_time":1421,"__count":9120232,"__max_score":1.0}}"

オンライン パーサーで実行したところ有効ですが、対応する番号が横にある町のリストにアクセスする方法がわかりません。

どんな助けでもいただければ幸いです

4

2 に答える 2

0

以下を使用して、町の「名前」と番号にアクセスできました。

var test = {
    "d": {
        "results": [],
        "facets": {
            "facet_counts": {
                "Town": {
                    "": 0,
                    "londonderry": 136914,
                    "london bridge": 1,
                    "london": 8983316,
                    "london colney": 1
                }
            }
        },
        "__solr_time": 3473457,
        "__ser_time": 1564,
        "__t_time": 1421,
        "__count": 9120232,
        "__max_score": 1
    }
}
for(var prop in test.d.facets.facet_counts.Town){
     console.log(prop);
     console.log(test.d.facets.facet_counts.Town[prop]);
}
于 2013-02-22T23:42:39.243 に答える
0

文字列に対して JSON.parse() を実行し、Townノードを引き出します。

var string; // the data string returned by API.
var dataObj = JSON.parse(string);
var Town = dataObj.d.facets.facet_counts.Town;

// access the properties as needed
var londonCount = Town.london;
var londonBridgeCount = Town['london bridge']; // need to use bracket notation to get this one
于 2013-02-22T23:47:05.447 に答える