Java net.sf.json.JSONException:JSONObject[";geonames";]不是JSONArray
我试图通过HTTP转换从json示例url中提取数据,然后使用java转换对其进行解析 在java转换中,我给出以下代码:Java net.sf.json.JSONException:JSONObject[";geonames";]不是JSONArray,java,json,informatica-powercenter,Java,Json,Informatica Powercenter,我试图通过HTTP转换从json示例url中提取数据,然后使用java转换对其进行解析 在java转换中,我给出以下代码: //converting the input stream HTTPOUT into JSON object JSONObject json = (JSONObject) JSONSerializer.toJSON(HTTPOUT); //Initializing JSON Array 'geonames' JSON
//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();
}
在导入包部分,我给出了以下包
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)
您的geonames值似乎无效。 检查打开和关闭方括号和花括号的位置。 它们看起来是有效的JSON吗? 如图所示固定支架,然后运行它
{“geonames”:{[/strong>“lng”:-99.12766456604,“geonamesid”:3530597,“cou”ntrycode“:“MX”,“名称”":"梅西科斯塔特俱乐部lName:“城市,村庄,…”,“地名”:“墨西哥城”,“fcodeName:“政治实体的首都”,“维基百科”:“en.wikipedia.org/wiki/Mexico_city”,“lat”":19.428472427036,“fcl:“P”,“人口”:12294193,“fcode”:“PPLC]}请显示JSONI如果我调用您的链接,我会得到以下Json对象:
{“status”:{“message”:“已超过演示每天30000学分的限制。请使用特定于应用程序的帐户。不要将演示帐户用于您的应用程序。”,“value”:18}
。它不包含名为geonames的元素
我不确定…我可以打开链接…让我与您共享数据集…{“geonames”:[{“lng”:-99.12766456604,“geonamesid”:3530597,“countrycode”:“MX”,“name”:“Mexiko Stadt”,“fclName”:“city,village…”,“地名”:“墨西哥城”,“fcodeName”:“政治实体的首都”、“维基百科”:“en.wikipedia.org/wiki/Mexico_City”、“lat”:19.428472427036,“fcl”:“P”、“population”:12294193,“fcode”:“PPLC”)}您的服务在进行呼叫时会收到什么HTTP状态码?
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)