1

如何从name":"offset","values":["90"]这个 JSON 字符串中的数组 paramList(在开头)中检索值 90?

{"query":{"query":"skole","hits":10,"paramList":[{"name":"hits","values":["10"]},{"name":"offset","values":["90"]},{"name":"q","values":["skole"]}]},"status":"success","facets":[{"selectionType":"AND","numberOfItems":1,"selectableItems":[{"value":"Intranett","displayName":"Intranett","count":146,"paramId":"?hits=10&q=skole&kilde=Intranett"}],"appliedItems":[],"facetName":"Kilde"},{"selectionType":"AND","numberOfItems":4,"selectableItems":[{"value":"EPiServerPage","displayName":"EPiServerPage","count":90,"paramId":"?hits=10&q=skole&type_s=EPiServerPage"},{"value":"Word","displayName":"Word","count":51,"paramId":"?hits=10&q=skole&type_s=Word"},{"value":"ClubNews","displayName":"ClubNews","count":4,"paramId":"?hits=10&q=skole&type_s=ClubNews"},{"value":"Project","displayName":"Project","count":1,"paramId":"?hits=10&q=skole&type_s=Project"}],"appliedItems":[],"facetName":"Type"}],"suggestions":{"displayName":"spellingSuggestion","suggestions":null,"collatedSuggestion":{"suggestion":null,"paramId":"?q=null"}},"errors":[],"numberOfHits":146,"pagination":{"offset":90,"first":{"displayName":"1","selected":false,"end":10,"start":1,"paramId":"?hits=10&q=skole&offset=1"},"next":{"displayName":"11","selected":false,"end":109,"start":100,"paramId":"?hits=10&q=skole&offset=100"},"hitsPerPage":10,"paginationItems":[{"displayName":"5","selected":false,"end":49,"start":40,"paramId":"?hits=10&q=skole&offset=40"},{"displayName":"6","selected":false,"end":59,"start":50,"paramId":"?hits=10&q=skole&offset=50"}, .....

为了检索元素查询(第一行的开头),我使用{$T.query.query}

4

4 回答 4

1

$T.query.query.paramList[1].values[0]假设结构不会改变

于 2012-09-12T15:49:18.043 回答
0

var val = jsonArray["query"]["paramList"][1]["values"];

var q = jsonArray["query"]["paramList"];

var values = q.map(function(){

    return values[0];

});

var index = values.indexOf(90);
于 2012-09-12T15:49:51.260 回答
0

如果您只查找该特定值并且知道它在 JSON 中的位置,则可以使用:

var json = 'YOUR JSON STRING HERE';
var obj = $.parseJSON(json);
var value = obj.query.paramList[1].values[0];
于 2012-09-12T15:51:09.990 回答
-1

您的 JSON 已评估

JSON.query.paramList[1].values.[0];

返回 90。

于 2012-09-12T15:51:13.363 回答