【发布时间】:2014-05-12 11:35:40
【问题描述】:
我正在尝试将 elasticsearch 与 android 应用程序集成。
我需要获取 jsonobject 并打印出每个 id 的详细信息。首先我需要尝试编写java类。
我可以只使用 json api 还是有一个更简单的 elasticsearch api。
网址:http://www.dummy.com:9200/contacts/index/_search
{
"took": 10,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 1.0,
"hits": [
{
"_index": "contacts",
"_type": "index",
"_id": "2",
"_score": 1.0,
"_source": {
"id": "c201",
"name": "Johnny Depp",
"email": "johnny_depp@gmail.com",
"address": "xx-xx-xxxx,x - street, x - country",
"gender": "male",
"phone": {
"mobile": "+91 0000000000",
"home": "00 000000",
"office": "00 000000"
}
}
},
{
"_index": "contacts",
"_type": "index",
"_id": "1",
"_score": 1.0,
"_source": {
"id": "c200",
"name": "Ravi Tamada",
"email": "ravi@gmail.com",
"address": "xx-xx-xxxx,x - street, x - country",
"gender": "male",
"phone": {
"mobile": "+91 0000000000",
"home": "00 000000",
"office": "00 000000"
}
}
}
]
}
}
【问题讨论】:
-
我已经设法从 url 获取 json 对象。但是现在要遍历每个联系人,我得到的 org.json.JSONObject 不能转换为 org.json.JSONArray。 @BlackPOP
-
感觉elasticsearch返回的json对象和正常的json响应字符串不一样。你能建议吗
标签: java json elasticsearch