我使用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
不是真的。这是我需要搜索的唯一两个字符串。这两个字符串都会触发结果的不同逻辑。 –