Wordpressブログからこのコンテンツを解析しています。から画像を取得する方法がわかりませんJSON
。これは画像のURLです"content":"<p><img class=\"aligncenter\" style=\"cursor: -moz-zoom-in;\" src=\"http:\/\/sphotos-h.ak.fbcdn.net\/hphotos-ak-ash4\/395050_10151219612828815_5123523_n.jpg\" alt=\"http:\/\/sphotos-h.ak.fbcdn.net\/hphotos-ak-ash4\/395050_10151219612828815_5123523_n.jpg\" width=\"390\" height=\"466\" \/><\/p>\n<p><span id=\"more-5267\"><\/span><\/p>\n<p>Some texts here...XXXXXYYYYYZZZZ"
HttpClient client;
HttpGet get;
HttpResponse res;
HttpEntity ent;
Button b;
TextView tv1,tv2,tv3;
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Typeface tp=Typeface.createFromAsset(getAssets(), "AftaSansThin-Regular.otf");
StrictMode.enableDefaults();
b = (Button) findViewById(R.id.button1);
tv1 = (TextView) findViewById(R.id.textView1);
tv2 = (TextView) findViewById(R.id.textView2);
tv3 = (TextView) findViewById(R.id.textView3);
tv1.setTypeface(tp);
tv2.setTypeface(tp);
tv3.setTypeface(tp);
client = new DefaultHttpClient();
get = new HttpGet("http://example.com");
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
res=client.execute(get);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ent=res.getEntity();
InputStream is = null;
try {
is=ent.getContent();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
BufferedReader br = new BufferedReader(new InputStreamReader(is));
StringBuffer sb = new StringBuffer();
String line = null;
do{
try {
line = br.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
sb.append(line);
} while (line!=null);
String str = sb.toString();
try {
JSONObject ob1 = new JSONObject(str);
JSONObject ob2 = ob1.getJSONObject("post");
String title = ob2.getString("title");
String date = ob2.getString("date");
String content = ob2.getString("content");
tv1.setText(title);
tv2.setText(date);
Spanned marked_up = Html.fromHtml(content);
tv3.setText(marked_up.toString(),BufferType.SPANNABLE);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}