Java 如何在android中从JSONArray提取JSONObject

Java 如何在android中从JSONArray提取JSONObject,java,android,json,Java,Android,Json,我只想从这个jsonarray中读取“value”对象 "body":{"und":[{"value":"hi friends!!!","summary":null,"format":null}]} 这是我的代码: protected void onPostExecute(final JSONObject result) { try { TextView lst2 = (TextView) findViewById(R.id

我只想从这个jsonarray中读取“value”对象

"body":{"und":[{"value":"hi friends!!!","summary":null,"format":null}]}  
这是我的代码:

  protected void onPostExecute(final JSONObject result) {



            try {
                TextView lst2 = (TextView) findViewById(R.id.View2);


                JSONArray cast = result.getJSONArray("body");
                for (int i=0; i<cast.length(); i++) {
                    JSONObject actor = cast.getJSONObject(i);
                    String name = actor.getString("value");
                    lst2.setText(name);
                }




            } catch (Exception e2) {
                Log.v("Error adding article", e2.getMessage());
            }


    } 
protectedvoid onPostExecute(最终JSONObject结果){
试一试{
TextView lst2=(TextView)findViewById(R.id.View2);
JSONArray cast=result.getJSONArray(“body”);

对于(inti=0;ibody不是其对象的数组,您需要首先将und作为JSONArray从body中取出

protected void onPostExecute(final JSONObject result) {



        try {
            TextView lst2 = (TextView) findViewById(R.id.View2);


            JSONArray cast = result.getJSONObject("body").getJSONArray("und");
            for (int i=0; i<cast.length(); i++) {
                JSONObject actor = cast.getJSONObject(i);
                String name = actor.getString("value");
                lst2.setText(name);
            }




        } catch (Exception e2) {
            Log.v("Error adding article", e2.getMessage());
        }


} 
protectedvoid onPostExecute(最终JSONObject结果){
试一试{
TextView lst2=(TextView)findViewById(R.id.View2);
JSONArray cast=result.getJSONObject(“body”).getJSONArray(“und”);

对于(int i=0;如果有帮助,请参阅此示例:代码中发生了什么/没有发生什么?此外,在这样的循环中设置文本只会将其设置为最后一个值(即,
cast.getJSONObject(cast.length()-1)
“body”:{“und”:[{“value”:“hi friends!!!,“summary”:null,“format”:null}}}中的任何内容都无效。