help with making a list of item names

help with making a list of item names

in API Development

Posted by: DarknessSkyX.9851

DarknessSkyX.9851

Hi all, I am new to this whole api programming thing and I need some help.

I have started to make a wrapper in java and I want to be able to get a list that contains the name of each item.

I started by using paging to get 200 items at one time, but I came to the realization that the loop would need to iterate 206 times before all of the items are in a list in addition to that i have an inner loop that adds the names to a list .

Is there a faster way to go about getting all the names, because it is incredibly slow right now? any help would be appreciated.

here is the loop i am using near the end of the loop there is an if statement that tests the size of the list of names and another variable of size. that size variable is the size of another list which contains all of the item ids



    		for(int x = 0; x < size; x++){
    			itemURL = itemURL + "?page=" + x + "&page_size=200";
    			newItemURL = new URL(itemURL);
    			p = getJsonArray(newItemURL);
    			g = (List<JSONObject> ) p;
    			
    			System.out.println("adding names to list");
    			
    			for(JSONObject q: g){
    				nameList.add( (String) q.get("name"));
        		}
    			
    			//reset the url
    			itemURL = "https://api.guildwars2.com/v2/items";
    			
    			//break the loop once the list is populated
    			if(nameList.size() >= size){
    				break;
    			}
    		}

help with making a list of item names

in API Development

Posted by: Lawton Campbell

Lawton Campbell

Web Programmer

The API only currently allows a max of 200 results/request, so you’re already fetching the data optimally. If you’re looking for raw speed, I’d recommend making the HTTP requests on one thread, then parsing the JSON on another in a producer-consumer fashion.

help with making a list of item names

in API Development

Posted by: DarknessSkyX.9851

DarknessSkyX.9851

The API only currently allows a max of 200 results/request, so you’re already fetching the data optimally. If you’re looking for raw speed, I’d recommend making the HTTP requests on one thread, then parsing the JSON on another in a producer-consumer fashion.

I didn’t even think about doing that thanks for the help i will give it a try and see how much of a speed difference there is