我正在从ElasticSearch获得响应,从该响应中我想形成另一个字段有限的JSON(例如自定义JSONObject)。请找到通过弹性搜索得到的响应。{ "took":93, "timed_out":false, "_shards":{ "total":5, "successful":5, "skipped":0, "failed":0 }, "hits":{ "total":1, "max_score":1.0, "hits":[ { "_index":"attachment", "_type":"doc", "_id":"87740", "_score":1.0, "_source":{ "app_language":"ES", "filetype":"PB", "attachment":{ "date":"2006-05-03T15:17:53Z", "content_type":"application/pdf", "author":"JJamesN", "language":"en", "title":"Microsoft Word - te7000pb.doc", "content":"European Electronic Controls Catalog ", "content_length":12267 }, "ext":"pdf", "fileContent":"JVBERi0xLjQNJeLjz9MNCjQ3ID" } } ] }}请找到我的Java代码,该Java代码试图操纵响应JSON以创建具有有限字段的单独JSON。JSONObject jsonObject = new JSONObject(responseBody);JSONObject hits = jsonObject.getJSONObject("hits");JSONArray hitsArray=hits.getJSONArray("hits");System.out.println("Hits---->"+hitsArray.toString());从响应JSON,我只想使用以下结构和字段创建一个新的JSON。 { "app_language":"ES", "filetype":"PB", "attachment.content" : "European Electronic Controls Catalog ", "ext":"pdf", }
1 回答
![?](http://img1.sycdn.imooc.com/54584cde0001d19202200220-100-100.jpg)
四季花海
TA贡献1811条经验 获得超5个赞
试试这个:
JSONObject jsonBody = new JSONObject();
jsonBody.put("app_language","value");
jsonBody.put("filetype","value");
jsonBody.put("attachment.content","value");
jsonBody.put("ext",ext);
//String requestBody = jsonBody.toString();
只需从响应中提取您的值,然后在任何需要的地方使用它即可。希望这可以帮助。
添加回答
举报
0/150
提交
取消