Google Voice 有 XML URL,所以我想知道如何从返回的 XML 中提取 JSON 部分并将其解析到页面。 Google Voice 的搜索功能现在已失效,我想访问我的历史记录。我认为对历史记录中最后一个已知页码之前的所有页面进行同步调用应该可以做到这一点......
最佳答案
这可能是您最好的选择...
在此处阅读有关数据类型转换的信息:http://api.jquery.com/extending-ajax/
特别是以下部分:
You can define converters "inline," inside the options of an ajax call. For example, the following code requests an XML document, then extracts relevant text from it, and parses it as "mydatatype":
$.ajax( url, {
dataType: "xml text mydatatype",
converters: {
"xml text": function( xmlValue ) {
// Extract relevant text from the xml document
return textValue;
}
}
});
我不知道这个确切的代码片段是否会正确返回 JSON 内容,但至少它应该将其从 XML 响应中删除(您可能需要添加额外的代码来将返回的“textValue”解析为JSON。也许使用 jQuery parseJSON
方法。
也许可以尝试一下:
$.ajax( url, {
dataType: "xml text mydatatype",
converters: {
"xml text": $.parseJSON;
}
}
});
希望这有帮助。
关于ajax - 如何提取 Google 语音数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4551197/