データを取得するために Web サイトとその API に接続しています。以下の私のコードはそれを行い、応答本文を取得しますが、その応答本文を解析するにはどうすればよいですか? 必要な用語を検索し、各用語のサブコンテンツを取得する独自の関数を作成する必要がありますか? または、私のためにそれを行うことができる、使用できるライブラリが既にありますか?
private class GetResultTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... urls) {
String response = "";
DefaultHttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet("https://api.bob.com/2.0/shelves/45?client_id=no&whitespace=1");
try {
HttpResponse execute = client.execute(httpGet);
InputStream content = execute.getEntity().getContent();
BufferedReader buffer = new BufferedReader(new InputStreamReader(content));
String s = "";
while ((s = buffer.readLine()) != null) {
response += s;
}
} catch (Exception e) {
e.printStackTrace();
}
return response;
}
@Override
protected void onPostExecute(String result) {
apiStatus.setText(result); //setting the result in an EditText
}
}
レスポンスボディ
{
"id": 415,
"url": "http://bob.com/45/us-state-capitals-flash-cards/",
"title": "U.S. State Capitals",
"created_by": "bub12",
"term_count": 50,
"created_date": 1144296408,
"modified_date": 1363506943,
"has_images": false,
"subjects": [
"unitedstates",
"states",
"geography",
"capitals"
],
"visibility": "public",
"has_access": true,
"description": "List of the U.S. states and their capitals",
"has_discussion": true,
"lang_terms": "en",
"lang_definitions": "en",
"creator": {
"username": "bub12",
"account_type": "plus",
"profile_image": "https://jdfkls.dfsldj.jpg"
},
"terms": [
{
"id": 15407,
"term": "Montgomery",
"definition": "Alabama",
"image": null
},
{
"id": 15455,
"term": "Juneau",
"definition": "Alaska",
"image": null
},
{
"id": 413281851,
"term": "Tallahassee",
"definition": "Florida",
"image": null
},
{
"id": 413281852,
"term": "Atlanta",
"definition": "Georgia",
"image": null
}
]
}