下面的代码是therasus同义词的代码。查询搜索词为"退款"我有以下代码
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
<div id="data"></div>
<script>
var urls = "http://words.bighugelabs.com/api/2/648c23bcbb99d535a06e098b426a5b76/refund/php";
$(document).ready(function() {
$.get(urls,function(data) {
$("#data").html(data);
});
});
</script>
</body>
</html>
我得到的回应是这样的:
a:2:{s:4:"noun";a:1:{s:3:"syn";a:4:{i:0;s:9:"repayment";i:1;s:8:"defrayal";i:2;s:10:"defrayment";i:3;s:7:"payment";}}s:4:"verb";a:1:{s:3:"syn";a:4:{i:0;s:6:"return";i:1;s:5:"repay";i:2;s:9:"give back";i:3;s:3:"pay";}}}
现在,我什至不明白这一点。我希望能够仅将响应的某些部分放入div 中......想要的词是这部分"合成"上的词:-
repayment
defrayal
defrayment
payment
return
repay
give back
pay
注意:搜索词(即退款)可能会根据用户查询而变化
这看起来很像 PHP 序列化格式: 序列化 PHP 字符串的结构
https://secure.php.net/manual/en/function.serialize.php
在此处查看文档:https://words.bighugelabs.com/api.php
您的 URL 以 /php
结尾,根据本文档,该 URL 返回序列化的 PHP 数组。您要调用http://words.bighugelabs.com/api/2/648c23bcbb99d535a06e098b426a5b76/refund/json
,请在末尾注意/json
。
您还在此处共享您的 API 密钥,最好将其编辑掉。如果您希望我删除答案,我会编辑它。
谢谢大家。
在@Walk的正确答案之后,我最终使用了
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
<p>
<button>Click</button>
<div id="data"></div>
<script>
var urls = "http://words.bighugelabs.com/api/2/648c23bcbb99d535a06e098b426a5b76/refund/json";
$("button").click(function(){
$.getJSON(urls, function(result){
$("#data").html("");
$.each(result, function(key1, value1){
$.each(value1, function(key, value){
$("#data").append(String(value).replace(/,/g,"<br>") + "<br>");
});
});
});
});
</script>
</body>
</html>