How to search for and retrieve java bean value with maximum performance

0

See if you can help me.

I have a service REST in PHP and it returns a JSON big enough! I'm using a library on Android " Volley " to cache this Json so far it works perfectly! Now I need to bring 4 updated fields in real time and play in my Class Bean, however as Json is great I do not know if the best way to do this would be to play in a loop repeat look for the ID field and then set the other 4 fields .

When I request the URL in this LIB Volley it already brings me the JSON cached, however these 4 fields are already set with values that do not match the database will not reflect with the actions of the user

I thought of separating the service into 2, one service brings me the fields that can stay in CACHE and the other service brings me these 4 fields in real time, now the question is the best technique to set these 4 fields in the bean with maximum performance?

My code:

private void parseJsonFeed(JSONObject response) {
    try {
        JSONArray feedArray = response.getJSONArray("feed");


        for (int i = 0; i < feedArray.length(); i++) {
            JSONObject feedObj = (JSONObject) feedArray.get(i);

            FeedItem item = new FeedItem();
            item.setId(feedObj.getInt("id"));
            item.setName(feedObj.getString("name"));

            // Image might be null sometimes
            String image = feedObj.isNull("image") ? null : feedObj
                    .getString("image");
            item.setImge(image);
            item.setStatus(feedObj.getString("status"));
            item.setProfilePic(feedObj.getString("profilePic"));
            item.setTimeStamp(feedObj.getString("timeStamp"));
            item.setLike(toBoolean(feedObj.getInt("like")));
            item.setClap(toBoolean(feedObj.getInt("clap")));
            item.setFavorite(toBoolean(feedObj.getInt("favorite")));
            //item.setSmile(feedObj.getString("timeStamp"));
            item.setHeart(toBoolean(feedObj.getInt("heart")));

            // url might be null sometimes
            String feedUrl = feedObj.isNull("url") ? null : feedObj
                    .getString("url");
            item.setUrl(feedUrl);

            feedItems.add(item);
        }

        // notify data changes to list adapater
        listAdapter.notifyDataSetChanged();
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

These 4 fields I need to update in real time

item.setLike(toBoolean(feedObj.getInt("like")));
item.setClap(toBoolean(feedObj.getInt("clap")));
item.setFavorite(toBoolean(feedObj.getInt("favorite")));
item.setHeart(toBoolean(feedObj.getInt("heart")));
    
asked by anonymous 07.02.2018 / 14:15

0 answers