java - Get Json with i.e 200 objects, but only 100 displayd on one site -


i'm working in twitch irc bot , got problem.

we receive alot of information through twitch api (json) followed, dateof .. viewercounts.. amount of followers , stuff that.

were making follow-function read names out of whole list , set our database. first off tried read , system.output them error: org.json.jsonexception: jsonarray[100] not found.

we noticed "0" holding array set loop 0-99 , should change link adding 100+ (next site) , read json again. should continue loop next site.

below main code read-methods.

we tried debugging wasn't able find solution yet x(

mybot main code snippet:

jsonobject follower = null; string followername = null; int listnumber;  offsetvalue = 0;  for(int = 0; < twitchstatus.totalfollows; i++) {       try {         follower = twitchstatus.followerarray.getjsonobject(i);     } catch (jsonexception e2) {         e2.printstacktrace();     }              try {         followername = follower.getjsonobject("user").getstring("display_name");     } catch (jsonexception e) {         e.printstacktrace();     }       system.out.println("array ist: "+i +" " +followername);      listnumber = offsetvalue+99; // 0+99      if (i == listnumber){         offsetvalue = offsetvalue+100;          try {             twitchstatus.followerticker();         } catch (ioexception e) {             e.printstacktrace();         } catch (jsonexception e) {             e.printstacktrace();         }     }     // system.out.println("follower abgleichs-liste: "+followername);         } 

and there reader method:

//////////////////////////////////////////////////////////////////////////////////// // twitch follower ticker ////////////////////////////////////////////////////////////////////////////////////  private string readall4(reader rd) throws ioexception {     stringbuilder sb = new stringbuilder();     int cp;     while ((cp = rd.read()) != -1) {         sb.append((char) cp);     }     return sb.tostring();   }    public jsonobject readjsonfromurl4(string url) throws ioexception, jsonexception {     inputstream = new url(url).openstream();     try {         bufferedreader rd = new bufferedreader(new inputstreamreader(is, charset.forname("utf-8")));         string jsontext = readall4(rd);         jsonobject json = new jsonobject(jsontext);         return json;     } {         is.close();     }   }    public static void followerticker() throws ioexception, jsonexception {     json = readjsonfromurl2("https://api.twitch.tv/kraken/channels/dotastarladder_en/follows?direction=desc&limit=100&offset="+mybot.offsetvalue+"");      followerarray = json.getjsonarray("follows");      {         jsonobject follower = followerarray.getjsonobject(0);         neuerfollower = follower.getstring("created_at");         fname = follower.getjsonobject("user").getstring("display_name");           totalfollows = json.getint("_total");     } }  

note api docs:

limit optional integer maximum number of objects in array. default 25. maximum 100.

so, do? query next one, of course! here's bit of json linked page, , example next url. basically, put offset in, url declares it, so...

{   "_total": 1234,   "_links": {     "next": "https://api.twitch.tv/kraken/channels/test_user1/follows?direction=desc&limit=25&offset=25", 

how solve problem this:

  1. create asynctask takes in url parse json text.
  2. when data has been received, start new task read next one.
  3. read received in json string
  4. compile after has been downloaded needed.

Comments

Popular posts from this blog

php - Magento - Deleted Base url key -

javascript - Tooltipster plugin not firing jquery function when button or any click even occur -

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -