Java codepublic class JsonUtil {
private static final String TAG = "JsonUtil";
private String result = "{\"posts\":[{\"post\":{\"news_id\":\"2\",\"news_title\":\"\u82f1\u7279\u5c14\u65b0\u95fb\u5217\u8868\",\"news_content\":\"\u82f1\u7279\u5c14\u65b0\u95fb\u5185\u5bb9(Inter..)\",\"news_time\":\"2012-07-13 11:08:09\"}},{\"post\":{\"news_id\":\"3\",\"news_title\":\"\u82f1\u7279\u5c14\u65b0\u95fb\u5217\u8868\",\"news_content\":\"\u82f1\u7279\u5c14\u65b0\u95fb\u5185\u5bb9(Inter..)\",\"news_time\":\"2012-07-13 11:08:25\"}},{\"post\":{\"news_id\":\"4\",\"news_title\":\"\u82f1\u7279\u5c14\u65b0\u95fb\u5217\u8868\",\"news_content\":\"\u82f1\u7279\u5c14\u65b0\u95fb\u5185\u5bb9(Inter..)\",\"news_time\":\"2012-07-13 11:15:57\"}}]}";
public void parseJson(){
JSONArray jsonArray;
try {
JSONObject jsonObject = new JSONObject(result);
String json_str = jsonObject.getString("posts");
jsonArray = new JSONArray(json_str);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jb = jsonArray.getJSONObject(i);
Log.i(TAG, jb.getString("post"));
JSONObject post = jb.getJSONObject("post");
Log.i(TAG,post.getString("news_id"));
Log.i(TAG,post.getString("news_title"));
Log.i(TAG,post.getString("news_content"));
Log.i(TAG,post.getString("news_time"));
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}