0
我有我想要的解析4「整理」只有結果如下JSON回覆:字符串轉換/解析返回正確的價值觀
jQuery191029421305245357143_1380819227858(
{
"responseHeader": {
"status": 0,
"QTime": 127
},
"command": "build",
"spellcheck": {
"suggestions": [
"restaurant",
{
"numFound": 1,
"startOffset": 0,
"endOffset": 10,
"suggestion": [
"restaurants"
]
},
"berl",
{
"numFound": 4,
"startOffset": 11,
"endOffset": 15,
"suggestion": [
"berlin",
"berlin brandenburg",
"berlin hamburg",
"berliner"
]
},
"collation",
"restaurant berlin",
"collation",
"restaurant (berlin brandenburg)",
"collation",
"restaurants berlin",
"collation",
"restaurant (berlin hamburg)"
]
}
}
)
在那裏我得到如下結果:
"restaurant"
"berl"
"restaurant berlin"
"restaurant (berlin brandenburg)"
"restaurants berlin"
"restaurant (berlin hamburg)"
與
success: function(data) {
response($.map(data.spellcheck.suggestions, function(item) {
if (typeof item != "string") return;
if (item === "collation") return;
return item;
}));
問題:如何只能拿到這4個結果:
"restaurant berlin"
"restaurant (berlin brandenburg)"
"restaurants berlin"
"restaurant (berlin hamburg)"
沒有兩個(錯誤)輸入結果(「restaurants」+「berl」)?
謝謝!
吧? if(item ===「collation」)return item; 但是你的JSON無效,它應該總是{「key」:「value」}並且你有{「key」,「key」} – Martin
@Martin:這隻會返回4x「整理」 – user2843661