我试图通过HTTP转换从json示例url http://api.geonames.org/citiesJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&lang=de&username=demo中提取数据,然后使用java转换来解析它。
在java转换中,我给出了以下代码:
//converting the input stream HTTPOUT into JSON object
JSONObject json = (JSONObject) JSONSerializer.toJSON(HTTPOUT);
//Initializing JSON Array 'geonames'
JSONArray geonames = json.getJSONArray("geonames");
//Looping through all the Array objects
for (int i = 0; i < geonames.size(); ++i) {
//Getting JSON Objects from the Array
JSONObject geoname = geonames.getJSONObject(i);
String lng = geoname.getString("lng");
lngOUT=lng;
String geonameId = geoname.getString("geonameId");
geonameIdOUT=geonameId;
String countrycode = geoname.getString("countrycode");
countrycodeOUT=countrycode;
String name = geoname.getString("name");
nameOUT=name;
// Generating rows in informatica
generateRow();
}
jar文件列表:
commons-io-2.4.jar;
commons-logging-1.2.jar;
commons-lang-2.6.jar;
commons-beanutils-1.9.2.jar;
json-lib-2.4-jdk15.jar;
ezmorph-1.0.6.jar;
commons-lang3-3.1.jar;
commons-collections-3.2.1.jar;
commons-beanutils-1.8.0.jar
在导入包部分,我已经给出了以下包。
import java.io.InputStream;
import java.lang.String;
import net.sf.json.JSONObject;
import net.sf.json.JSONArray;
import net.sf.json.JSONSerializer;
在java类路径中,我提到了所有使用的外部jar文件。 ETL作业因以下错误而失败:
Message Code: JAVA PLUGIN_1762
Message: [ERROR] net.sf.json.JSONException: JSONObject["geonames"] is not a JSONArray.at net.sf.json.JSONObject.getJSONArray(JSONObject.java:2038)
at com.informatica.powercenter.server.jtx.JTXPartitionDriverImplGen.execute(JTXPartitionDriverImplGen.java:161)
答案 0 :(得分:0)
您的地理位置值似乎无效。 检查方括号和花括号的开合位置。 他们似乎是有效的JSON? 如此处所示修复括号,然后运行它。
{ “GEONAMES”:<强> {[强> “LNG”: - 99.12766456604, “geonameId”:3530597, “凑ntrycode”: “MX”, “名称 ”:“ Mexiko-施塔特” ,“fc lName”:“city,village,...”,“toponymName”:“墨西哥城”,“fcodeName”:“政治实体的首都”,“维基百科”:“en.wikipedia.org/wiki /墨西哥城 “ ”LAT “:19.428472427036,” F CL“: ”P“, ”人群“:12294193, ”FCODE“:” P PLC]}