我使用jQuery中的AJAX調用從API中檢索JSON對象。這是我收到回一個例子對象:如何使用jQuery在對象內搜索特定字符串的JSON對象
...
"batchcomplete": "",
"query": {
"normalized": [
{
"from": "star trek",
"to": "Star trek"
}
],
"pages": {
"1048985": {
"pageid": 1048985,
"ns": 0,
"title": "Star trek",
"extract": "<ul><li><b>From other capitalisation</b>: This is a redirect from a title with another method of capitalisation. It leads to the title in accordance with the Wikipedia naming conventions for capitalisation, or it leads to a title that is associated in some way with the conventional capitalisation of this redirect title. This may help writing, searching and international language issues.\n<ul><li>If this redirect is an incorrect capitalisation, then {{R from miscapitalisation}} should be used <i>instead</i>, and pages that use this link should be updated to link <i>directly</i> to the target. Miscapitisations can be tagged in <i>any namespace</i>.</li>\n<li>Use this rcat to tag <i>only</i> mainspace redirects; when other capitalisations are in other namespaces, use {{R from modification}} <i>instead</i>.</li>\n</ul></li>\n</ul>"
}
}
}
}
我還有一個JSON對象回來,看起來像這樣:
{
"batchcomplete": "",
"query": {
"normalized": [
{
"from": "set",
"to": "Set"
}
],
"pages": {
"454886": {
"pageid": 454886,
"ns": 0,
"title": "Set",
"extract": "<p><b>Set</b> or <b>The Set</b> may refer to:</p>\n\n"
}
}
}
}
什麼,我試圖做的是尋找這些對象的特定字符串以便對結果執行邏輯以檢索我實際正在查找的數據。在第一個例子中,我想在「extract」值中找到'From other capitalization',而在第二個例子中,我想找到'可能指:'。
有沒有辦法爲特定的字符串搜索特定的JSON對象並返回該字符串是否存在?
所以,你每次需要不同的字符串? – br3t
不是真的。這是我需要搜索的唯一兩個字符串。這兩個字符串都會觸發結果的不同邏輯。 –