我已经解析了一些 JSON,但我想获取从 JSON 获得的链接,在链接中找到一个使其不同的标识符(例如 www.foo.com/IDENTIFIER/home),并拥有该标识符作为一个字符串插入到另一个使用标识符的函数中。
这是我尝试使用 indexOf 查找前置标识符路径索引的代码,这样我就可以在它之后获取标识符的索引(该代码尚未编写,因为我被困在这里)。这也使用 JSONP。
$.jsonp({
"url": "http://foo.com&callback=?",
"data": {
"alt": "json-in-script"
},
"success": function (data) {
var link = data[0].link;
var jsonText = JSON.stringify(link);
// the below code returns string
console.log('jsonText string?'+typeof jsonText);
// the below code returns that this method has no object indexOf
var index = jsonText.indexof("pre-identifier-path/");
},
"error": function () {
}
});
感谢您抽出宝贵时间,如果这有点令人困惑,我们深表歉意。
最佳答案
该方法应命名为 indexOf
,区分大小写。例如:
jsonText.indexOf("pre-identifier-path/");
关于javascript - 无法在 JSON 字符串上使用 .indexof,因为它没有方法 'indexof' javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7108252/