Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
43 lines (39 sloc) 1.2 KB
#~
# compile: obc -src json_3.obs -lib gen_collect.obl,json.obl,net_misc.obl,gen_collect.obl -dest json_3.obe
# run: obr json_3.obe
~#
use Data.JSON;
use Web.HTTP;
use System.IO.Net;
class JsonWeb {
function : Main(args : String[]) ~ Nil {
Run();
}
function : native : Run() ~ Nil {
url := "http://api.geonames.org/citiesJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&lang=de&username=objeck";
document := HttpClient->GetAll(url);
parser := JSONParser->New(document);
root := parser->Parse();
if(root <> Nil & root->GetType() = JSONType->OBJECT) {
geonames := root->Get("geonames");
if(geonames <> Nil & geonames->GetType() = JSONType->ARRAY) {
each(i : geonames) {
geoname := geonames->Get(i);
if(geoname <> Nil & geoname->GetType() = JSONType->OBJECT) {
toponymName := geoname->Get("toponymName");
lng := geoname->Get("lng");
lat := geoname->Get("lat");
if(toponymName <> Nil & lng <> Nil & lat <> Nil) {
toponymName->GetValue()->PrintLine();
"name={$toponymName}, lat={$lat}, lon={$lng}"->PrintLine();
};
"-------------"->PrintLine();
};
};
};
}
else {
document->PrintLine();
};
}
}
You can’t perform that action at this time.