我正在MediaWiki API的帮助下获取有关某些动物的一些信息
http://en.wikipedia.org/w/api.php?action=query\u0026amp;prop=extracts\u0026amp;titles=Animal\u0026amp;format=json\u0026amp;exintro=1
但是对象之一是根据动物而变化的页面.如何访问页面对象(包含有关动物的摘录)?
这是JSON查询结果
{
"batchcomplete":"","warnings":{ },"query":{
"pages":{
"6598":{
"pageid":6598,"ns":0,"title":"Camel","extract":"<p class=\"mw-empty-elt\">\n</p>\n<p>A <b>camel</b> is
an even-toed ungulate in the genus <i>Camelus</i> that bears
distinctive fatty deposits known as \"humps\" on its back.
Camels have long been domesticated and,as livestock,they
provide food (milk and meat) and textiles (fiber and felt from
hair). As working animals,camels\u2014which are uniquely suited
to their desert habitats\u2014are a vital means of transport for
passengers and cargo. There are three surviving species of
camel."
}
}
}
}
最佳答案
您应该考虑以下几点:
>仅在响应时查找响应状态代码,例如:
onResponse(){
如果(statusCode == 200){
// —现在在这里查找特定于响应的主体
}
}
>使用JsonObject作为响应主体的模型,例如:
@Override
public void onResponse(Call < JsonObject > call,Response < JsonObject > response) {
if (response.code() == 200) {
if (!response.body().toString().isEmpty()) {
// ----- Now Here You can Extract the JsonObject Field you are looking for
// --- Example :
JsonObject object = response.body();
String target = object.get("field_name);
} else {
// Empty Response
}
} else {
// Failure or whatever
}
}
您如何获得此回复?翻新,凌空,OkHttp?
每个都提供了一些易于解决的方法来更改字段
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。