-1
我想从Google URL API中提取长URL。以下是代码片段,我试图继续: `StringBuilder url = new StringBuilder(URL); url.append(shortUrl);字符串不能转换为JSONArray Android
HttpGet get = new HttpGet(url.toString());
HttpResponse r = client.execute(get);
int status = r.getStatusLine().getStatusCode();
if(status == 200){
HttpEntity e = r.getEntity();
String data = EntityUtils.toString(e);
JSONObject jsonObj = new JSONObject(data);
JSONArray ja = jsonObj.getJSONArray("longUrl");
JSONObject last = ja.getJSONObject(0);
return last;
包含代码的函数返回一个JSON对象。在logcat,我看到一个错误org.json.JSONException: Value http://www.google.com/ at longUrl of type java.lang.String cannot be converted to JSONArray
该代码正在接收完整的url(http://www.google.com),但我做了JSONArray错误。
在一个侧面说明:这从谷歌API的响应:'{ “种”: “urlshortener#URL”, “ID”: “http://goo.gl/fbsS”, “longUrl”: “http://www.google.com/”, “状态”:“确定” }' – Paritosh
已经尝试过。似乎没有工作。 – Paritosh