0

I have been working on getting data from JSON API for wordpress from https://wordpress.org/plugins/json-api/other_notes/

I have used the follwing to fetch data. Everything is working fine except that it is taking about 30 seconds to load data on to the tabview.

try {

            JSONObject jObj = new JSONObject(result);

            int count = (jObj.getInt("count_total"));


            JSONArray jArray = jObj.getJSONArray("posts");



            //  Toast.makeText(getApplicationContext(), "Year: " + date2.substring(0, 4) + "Hour: " + date2.substring(11, 13), Toast.LENGTH_SHORT).show();
            //  Toast.makeText(getApplicationContext(),"Hour: "+date2.substring(11,13),Toast.LENGTH_SHORT).show();
            // Extract data from json and store into ArrayList as class objects

            for (int i = 0; i < jArray.length(); i++) {
                JSONObject json_data = jArray.getJSONObject(i);

                JSONArray jArray2 = json_data.getJSONArray("categories");
                JSONObject json_data2 = jArray2.getJSONObject(0);


                DataFish fishData = new DataFish();
                fishData.fishImage = json_data.getString("thumbnail");

                fishData.fishName = json_data.optString("title", "N/A");

                String comment = json_data.optString("comment_count", "0");
                fishData.comment = comment;
                 //fishData.fishName ="Title";

                //  fishData.sizeName = json_data.getString("size_name");
                String category_array = json_data2.optString("title", "N/A");


                fishData.sizeName = category_array;
                fishData.price = 10;
                fishData.url =
                        json_data.optString("url", "N/A");
                data.add(fishData);


            }
}

Any other way to fetch data faster so that user need not wait for awful 25-30 seconds to load data?

3
  • how many post are you getting from wp? Commented Jan 6, 2017 at 15:46
  • @PabloCegarra Only 5 posts at a time Commented Jan 6, 2017 at 15:49
  • and the delay time is parsing the json or requesting the data? Commented Jan 6, 2017 at 15:51

1 Answer 1

0

you should use the new and highly used library for JSON or xml api integration or data convert library.

// retrofit, gson
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.squareup.retrofit2:retrofit:2.0.2'
compile 'com.squareup.retrofit2:converter-gson:2.0.2'

and also see this link it help you that how to implement or use this

http://www.androidhive.info/2016/05/android-working-with-retrofit-http-library/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.