我已经解析了一些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/