综合技术

Adding JSON data to arrayList

微信扫一扫,分享到朋友圈

Adding JSON data to arrayList
0

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 myJSONArray = new ArrayList();

         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.

阅读原文...


Hello, buddy!

Book Memo: “Singular Spectrum Analysis with R”

上一篇

Layout Design - Android

下一篇

您也可能喜欢

评论已经被关闭。

插入图片
Adding JSON data to arrayList

长按储存图像,分享给朋友