添加JSON数据的ArrayList数据、JSON、ArrayList

由网友(姑凉~引领风骚)分享简介:仍然工作在这部分我的脚本来分析我的JSON jsonArray =新JSONArray(jsonData); ,然后将其添加到一个数组列表myJSONArray我不知道如何在for循环将努力增加从jsonArray我的元素融入myJSONArray(ArrayList中)如果我不清楚,请让我知道,如果有任何信息,我缺...

仍然工作在这部分我的脚本来分析我的JSON jsonArray =新JSONArray(jsonData); ,然后将其添加到一个数组列表myJSONArray

我不知道如何在for循环将努力增加从jsonArray我的元素融入myJSONArray(ArrayList中)

如果我不清楚,请让我知道,如果有任何信息,我缺少的只是问问。先谢谢了。

JSON数据:

{"id":["1","2","3"],"name":["Dragon","Butterfly","Tattoo"],"thumb":["thm_polaroid.jpg","thm_default.jpg","thm_enhanced-buzz-9667-1270841394-4.jpg"],"path":["polaroid.jpg","default.jpg","enhanced-buzz-9667-1270841394-4.jpg"]}

类IMAGE_DATA:

 公共类{IMAGE_DATA


    公众诠释ID;
    公共字符串名称;
    公共字符串大拇指;
    公共字符串路径;


}
 
MongoDB导入json数据

ShowThumb类:

 公共类showThumb延伸活动{



    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.gridlayout);

         束束= getIntent()getExtras()。
         串jsonData = bundle.getString(jsonData);


         JSONArray jsonArray = NULL;
        尝试 {
            jsonArray =新JSONArray(jsonData);
        }赶上(JSONException E){
            // TODO自动生成的catch块
            e.printStackTrace();
        }

        ArrayList的<&IMAGE_DATA GT; myJSONArray =新的ArrayList<&IMAGE_DATA GT;();

         的for(int i = 0; I< jsonArray.length();我++){
               ** //这是我认为我创建ID名称拇指和路径的独立阵列**
             myJSONArray.add(新IMAGE_DATA());

         }


GridView控件的GridView =(GridView控件)findViewById(R.id.gridview);
        gridview.setAdapter(新ImageAdapter(这一点,IMAGE_DATA));

    }
}
 

解决方案

您如何迭代,并添加

 的for(int i = 0; I< jsonArray.length;我++)
    {
         的JSONObject json_data = jArray.getJSONObject(ⅰ);
         imgnfo.id = json_data.getInt(id_key);
         imgnfo.name = json_data.getString(name_key);
         imgnfo.thumb = json_data.getString(thumb_key);
         imgnfo.info = json_data.getString(info_key);
         myArray.add(新IMAGE_DATA());
    }
 

只需添加适当的键名。我不知道他们。

Still working on this part of my script to parse my JSON jsonArray = new JSONArray(jsonData); and then adding it to a arraylist "myJSONArray"

I am not sure how the for loop would work to add my elements from jsonArray into myJSONArray (arrayList)

If I am not clear please let me know and if there is any info I am missing just ask. Thanks in advance.

JSON data:

{"id":["1","2","3"],"name":["Dragon","Butterfly","Tattoo"],"thumb":["thm_polaroid.jpg","thm_default.jpg","thm_enhanced-buzz-9667-1270841394-4.jpg"],"path":["polaroid.jpg","default.jpg","enhanced-buzz-9667-1270841394-4.jpg"]}

image_data class:

public class image_data {


    public int id;
    public String name;
    public String thumb;
    public String path;


}

ShowThumb class:

public class showThumb extends Activity{



    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.gridlayout);

         Bundle bundle = getIntent().getExtras();
         String jsonData = bundle.getString("jsonData");


         JSONArray jsonArray = null;
        try {
            jsonArray = new JSONArray(jsonData);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        ArrayList<image_data> myJSONArray = new ArrayList<image_data>();

         for (int i=0; i<jsonArray.length(); i++) {
               **//This is where I think I create the seperate arrays of id name thumb and path**
             myJSONArray.add(new image_data());

         }


GridView gridview = (GridView) findViewById(R.id.gridview);
        gridview.setAdapter(new ImageAdapter(this,image_data));

    }
}

解决方案

How you iterate and add

 for(int i=0;i<jsonArray.length;i++)
    {    
         JSONObject json_data = jArray.getJSONObject(i);
         imgnfo.id =  json_data.getInt("id_key");
         imgnfo.name = json_data.getString("name_key");
         imgnfo.thumb = json_data.getString("thumb_key");
         imgnfo.info = json_data.getString("info_key");
         myArray.add(new image_data());
    }

Just add proper keys names. I didn't know them.

阅读全文

相关推荐

最新文章