【发布时间】:2011-08-18 13:34:09
【问题描述】:
我解析了一些 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 () {
}
});
感谢您的宝贵时间,如果这有点令人困惑,抱歉。
【问题讨论】:
标签: javascript json jsonp