0
我想从JSON数组中获取JSON字符串,但得到这个错误,任何帮助将高度赞赏,JSON合成器给出了波纹管,请帮助别人。 错误是波纹管值java.lang.String类型的HTTPS无法转换为JSONArray
05-29 12:37:22.600 25505-25505/com.akasha.mongodataapi W/System.err: org.json.JSONException: Value https of type java.lang.String cannot be converted to JSONArray
05-29 12:37:22.610 25505-25505/com.akasha.mongodataapi W/System.err: at org.json.JSON.typeMismatch(JSON.java:111)
05-29 12:37:22.610 25505-25505/com.akasha.mongodataapi W/System.err: at org.json.JSONArray.<init>(JSONArray.java:96)
05-29 12:37:22.610 25505-25505/com.akasha.mongodataapi W/System.err: at org.json.JSONArray.<init>(JSONArray.java:108)
它是JSON的甲酸
[ { "_id" : { "$oid" : "57472009a0fdab7cc3c"} , "name" : "Sasha Burni" , "sort" : "Sasha"} ,
{ "_id" : { "$oid" : "57472009afdab7cc3d"} , "name" : "Akasha Khail" , "sort" : "Akasha"}]
和Java代码是波纹管
String url="https://api.mlab.com/api/1/databases/picasanovels/collections/Country?apiKey=myapikey";
try {
JSONArray jArr = new JSONArray(url);
for (int count = 0; count < jArr.length(); count++) {
JSONObject obj = jArr.getJSONObject(count);
String name = obj.getString("name");
System.out.println("Name Printed :"+name);
//so on
}
} catch (JSONException e) {
e.printStackTrace();
}
它看起来像它试图您的网址转换成JSON阵列。你必须进行GET请求才能获取该URL的内容,然后将该内容作为参数传递给JSONArray对象 – bwalshy
您是不是将url转换为String类型为json数组?我想你想要转换http请求的响应,而不是你所做的。 使用一些http客户端,如Unirest或apache http客户端发出请求。 – user1211
感谢您的早期回复,但是如果有一些例子会很容易理解。 –