我有一个JSON文件,它看起来像这样搜索并获得有限的搜索结果
[{
"id": "2",
"word": "Aam",
"type": "n.",
"descr": " A Dutch and German measure of liquids, varying in different cities, being at Amsterdam about 41 wine gallons, at Antwerp 36 1\/2, at Hamburg 38 1\/4.",
"track": "a",
"track_2": "Aa",
"track_3": "Aam"
}, {
"id": "3",
"word": "Aard-vark",
"type": "n.",
"descr": " An edentate mammal, of the genus Orycteropus, somewhat resembling a pig, common in some parts of Southern Africa. It burrows in the ground, and feeds entirely on ants, which it catches with its long, slimy tongue.",
"track": "a",
"track_2": "Aa",
"track_3": "Aar"
}, {
"id": "4",
"word": "Aard-wolf",
"type": "n.",
"descr": " A carnivorous quadruped (Proteles Lalandii), of South Africa, resembling the fox and hyena. See Proteles.",
"track": "a",
"track_2": "Aa",
"track_3": "Aar"
}, {
"id": "5",
"word": "Aaronic",
"type": "a.",
"descr": " Alt. of Aaronical",
"track": "a",
"track_2": "Aa",
"track_3": "Aar"
}, {
"id": "6",
"word": "Aaronical",
"type": "a.",
"descr": " Pertaining to Aaron, the first high priest of the Jews.",
"track": "a",
"track_2": "Aa",
"track_3": "Aar"
}, {
"id": "7",
"word": "Aarons rod",
"type": "",
"descr": " A rod with one serpent twined around it, thus differing from the caduceus of Mercury, which has two.",
"track": "a",
"track_2": "Aa",
"track_3": "Aar"
}, {
"id": "8",
"word": "Aarons rod",
"type": "",
"descr": " A plant with a tall flowering stem; esp. the great mullein, or hag-taper, and the golden-rod.",
"track": "a",
"track_2": "Aa",
"track_3": "Aar"
}]
我想获得前2或3的结果的其中一句话=“AA”,track_2 =“AA”, track_3 =“aar”..我该怎么做?
我需要
1.查询JSON中通过什么字符串 2.获取有限的结果 3.我想2-3的条件
我想要在JSON文件中搜索这
$(window).load(function() {
$('#search').keyup(function() {
var searchField = $('#search').val();
$.getJSON('files/aa.json', function(data) {
var jsonArrr = data;
var matchMe = new RegExp('^' + searchField, 'i');
var matches = [];
for (var i in jsonArrr) {
if (jsonArrr[i].word.search(matchMe) > -1) {
matches.push({
'id': jsonArrr[i].word,
'word': jsonArrr[i].word
});
}
}
for (var i in matches) {
console.log(matches[i].word);
}
});
});
});
有没有办法让我需要扩大一些代码?
你不解析JSON成一个对象,只是比较性质的原因吗? – Shilly
我认为这行' - id':jsonArrr [i] .word'应该改为''id':jsonArrr [i] .id' –
我使用json文件作为firefoxOS的离线数据库,这就是为什么我'解析JSON到一个对象@Shilly –