java - JSON Url returns something else? -


i trying access json file : http://www.cloudpricingcalculator.appspot.com/static/data/pricelist.json java.

but when read it, gives me json string (that's ok) , gives me else , json.simple.parser throw unexpected character(<) @ position 0. based on read on stackoverflow, may returns xml instead of json. url "json", how possible ?

here code i'm using :

string baseurl = "http://www.cloudpricingcalculator.appspot.com/static/data/pricelist.json"; ... url url = new url(this.baseurl); bufferedreader in = new bufferedreader(new inputstreamreader(url.openstream())); string l; string json = ""; system.out.println(url); while((l=in.readline()) != null){   system.out.println(l);   json+=l; } jsonparser parser = new jsonparser(); jsonobject jsonobject = (jsonobject) parser.parse(json); 

and log <followed lot of squares , unknown characters ÿÕ[s›È , error unexpected character () @ position 0.

you not taking account compression , encoding of resource returned server. response of head request following:

rpax@machine:~$ head http://www.cloudpricingcalculator.appspot.com/static/data/pricelist.json 200 ok cache-control: public, max-age=600 connection: close date: mon, 21 aug 2017 12:02:14 gmt age: 112 etag: "n_s_jq" server: google frontend content-encoding: gzip <---- *here* content-length: 7902 content-type: application/json expires: mon, 21 aug 2017 12:12:14 gmt ... 

for avoiding issue, can wrap url stream gzipinputstream :

gzipinputstream gis = new gzipinputstream(url.openstream()); bufferedreader in = new bufferedreader(new inputstreamreader(gis)); // ... 

and data returned when executing readline() decompressed.


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -