Adding JSON data to arrayList

综合技术 2018-07-16 阅读原文

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:


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) {

         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

        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(;
        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); =  json_data.getInt("id_key"); = json_data.getString("name_key");
         imgnfo.thumb = json_data.getString("thumb_key"); = json_data.getString("info_key");
         myArray.add(new image_data());

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

Hello, buddy!

责编内容by:Hello, buddy!阅读原文】。感谢您的支持!


Android_简易的短信发送器 这个随笔将介绍如何完成一个简单的第三方的短信发送器(不打开短信界面,调用android的api完成功能) 1.首先,我们来做布局 由于我这里写的是一个简易的,,短信发送,所以只是一个LinearLayout下放了两个EditText...
SnapTabLayout SnapTabLayout This library is the implementation of TabLayout as seen on popular messaging app Snapchat Snapchat....
Expo for Professionals Coming to Expo: a new open-source repo, TypeScript, best-in-class APIs, custom native code, more platforms, and much mor...
java.lang.ClassCastException: 背景: Android8.0 之后图标需要兼容方案 多了个圆形的图标兼容完之后获取图标出现了 java.lang.ClassCastException:
Outlook extension commands VersionOverrides and un... How to complete Outlook Outlook (extension) automatically? I develope a outlook extension(add-ins)...