我正在尝试使用 JSONP 帖子通过 JavaScript 客户端应用程序测试调用 Alchemy News API。
我的 JSON 结果如下所示:
<results>
<status>OK</status>
<usage>
By accessing AlchemyAPI or using information generated by AlchemyAPI
</usage>
<totalTransactions>50</totalTransactions>
<result>
<docs>
<element>
<id>ODE0ODI3NTg3MHwxNDUzMzc2NDkz</id>
<source>
<enriched>
<url>
<title>
Mich. Company Offers $15 Million To Acquire Firm
</title>
</url>
</enriched>
</source>
<timestamp>1453376493</timestamp>
</element>
我可以使用以下代码成功调用 API(取自How do I get the JSON from an API request into my page's javascript?)
function loadDoc() {
$.ajax({
url: 'https://gateway-a.watsonplatform.net/calls/data/GetNews?apikey=MY_KEY&outputMode=json&outputMode=json&start=now-7d&end=now&count=1&return=enriched,original',
dataType: 'jsonp',
jsonp: 'jsonp',
type: "get",
success: function (res) {
if (res["status"] === "OK") {
alert("Good!");
}
else if (res["status"] === "ERROR") {
alert("Bad!");
}
},
error: function (jqxhr) {
//console.log(jqxhr);
}
});
}
我真正苦苦挣扎的是访问返回对象中的数据。我可以毫无问题地读取诸如状态
之类的
顶级值,但我似乎可以从架构中更深层次的信息中加载任何值。
谁能发布我如何访问标题字段中的数据?
提前谢谢了。