in my tests, the page returns an empty array. ( if (lines.length<=0))
This you have to skip (with continue command).
(maybe they return empty lines when too much inquiries from the same IP occur??)
No use to test for the first char in this case.
TRIM
But I used trim() on the String before parsing it which seemed to help
lines[0] = trim(lines[0]);
JSONObject link = parseJSONObject(lines[0]);
Result
here is one result:
(but the results were different every time)
(one star is one empty line)
0 2 { Cannonball
1 6 { Cannon base
2 8 { Cannon stand
3 10 { Cannon barrels
4 12 { Cannon furnace
5 36 { Candle
6 39 { Bronze arrowheads
7 40 { Iron arrowheads
8 41 { Steel arrowheads
9 42 { Mithril arrowheads
10 43 { Adamant arrowheads
11 44 { Rune arrowheads
12 45 { Opal bolt tips
13 46 { Pearl bolt tips
14 47 { Barb bolttips
*****************33 157 { Super strength (3)
****38 269 { Clean torstol
************51 1050 { Santa hat
52 1149 { Dragon helm
*****
Chrisir
Code
int idNum = 0;
int[] idArray={
2,
6,
8,
10,
12,
36,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
50,
52,
53,
54,
56,
58,
60,
62,
64,
66,
68,
70,
72,
95,
125,
127,
139,
157,
173,
191,
201,
211,
269,
303,
385,
438,
528,
550,
575,
600,
650,
843,
868,
991,
1031,
1050,
1149,
1189,
1291,
1355,
1379,
1444
};
// --------------------------------------------------------------------------------------------------------------------
void setup() {
size(500, 500);
noLoop();
// idArray = loadStrings("allIds.txt");
}
void draw() {
for (int i = 0; i < idArray.length; i++) {
idNum = int(idArray[i]);
String[] lines = null;
lines=loadStrings("http://services.runescape.com/m=itemdb_rs/api/catalogue/detail.json?item=" + idNum);
if (lines.length<=0) { // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
print("*");
//printArray(lines);
continue; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
}
// println("test 1");
// printArray(lines);
char first = trim(lines[0]).charAt(0);
// println( i, first );
// you get the idea ? now change your following original code
//if (first=='{')
// println("OK");
lines[0] = trim(lines[0]);
JSONObject link = parseJSONObject(lines[0]);
// --------------------------------------------
// JSONObject link = loadJSONObject("http://services.runescape.com/m=itemdb_rs/api/catalogue/detail.json?item=" + idNum);
JSONObject itemData = link.getJSONObject("item");
String name = itemData.getString("name");
println(i+" "+idNum+" "+first+" "+ name);
/*
catch (Exception e) {
JSONArray link = loadJSONArray("http://services.runescape.com/m=itemdb_rs/api/catalogue/detail.json?item=" + idNum);
for (int j = 0; j < link.size(); j++) {
JSONObject values = link.getJSONObject(i);
String score = values.getString("name");
println(i+" "+idNum+" "+first+" "+ score);
}
}
*/
delay(2110);
}//for
// end message
println("");
println("-----------------------------------------------------------------------------------------");
}
//