我想解析嵌套的JSON像這樣JSON解析嵌套的JSON與凌空
,但我不與前嵌套JSON的工作,我知道解析JSON對象和數組孤單,但我不知道嵌套json解析。 iwant得到posts
title
並獲得tumbnail_images
我寫一些代碼TUMBNAIL url,但我有一個錯誤
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, (String) null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
final String posts = response.getString("posts");
// ================================================ Json Array Request
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, url, (String) null, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
String arrayResponse = "";
try {
for (int i = 0; i < response.length(); i++) {
JSONObject post = (JSONObject) response.get(i);
String title = post.getString("title");
arrayResponse += "title : " + title;
}
}
catch (JSONException e) {
e.printStackTrace();
}
//btnShow ClickListener
btnShowPost.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
txtShowPosts.setText(arrayResponse);
}
});
}
}
},new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this, "We have a problem in Array Request ", Toast.LENGTH_SHORT).show();
}
});
jsonResponse = "";
jsonResponse += "posts " + posts;
);
}
catch(
JSONException e
)
{
e.printStackTrace();
Toast.makeText(MainActivity.this, "We have a problem ", Toast.LENGTH_SHORT).show();
}
}
}
,new Response.ErrorListener()
{
@Override
public void onErrorResponse (VolleyError error){
Toast.makeText(MainActivity.this, "We have a problem in volley ", Toast.LENGTH_SHORT).show();
}
}
);
AppController.getInstance().addToRequestQueue(jsonObjectRequest);
你可能想閱讀[我如何問一個好問題](http://stackoverflow.com/help/how-to-ask),這增加了得到一個有用的答案_drastically_。你可能會發現[ESR](https://en.m.wikipedia.org/wiki/Eric_S._Raymond)的優秀論文[如何提問智能方式](http://catb.org/~esr/) faqs/smart-questions.html)也很有幫助。 –