[英]java.lang.IllegalArgumentException:llegal character in query at index 77 in Android
I am trying to parse Facebook feed using json 我正在尝试使用json解析Facebook feed
it show this error 它显示此错误
06-02 16:53:33.112: D/ee:(29180): java.lang.IllegalArgumentException: Illegal character in query at index 77: https://graph.facebook.com/331394590231184/feed?access_token= ******&client_id=**&client_secret=*****?
06-02 16:53:33.112:D / ee:(29180):java.lang.IllegalArgumentException:索引77处查询中的非法字符: https ://graph.facebook.com/331394590231184/feed?access_token = *** ***&client_id = **&client_secret = *****?
i use code : 我使用代码:
private static String url = "https://graph.facebook.com/331394590231184/feed?access_token=**|*****&client_id=***&client_secret=****";
JSONParser jParser = new JSONParser();
List<NameValuePair> params = new ArrayList<NameValuePair>();
JSONObject json = jParser.makeHttpRequest(url, "GET", params);
JSONArray data = json.getJSONArray("data");
JSONParser code : JSONParser代码:
static InputStream is = null;
DefaultHttpClient httpClient = new DefaultHttpClient();
String paramString = URLEncodedUtils.format(params, "utf-8");
url += "?" + paramString;
HttpGet httpGet = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
You're building an invalid URL with multiple ?
您正在建立一个无效的URL,其中包含多个
?
in it, you should pass just the scheme, host, and path as the url
variable, and then pass the params separately: 在其中,您应该只传递方案,主机和路径作为
url
变量,然后分别传递参数:
private static String url = "https://graph.facebook.com/331394590231184/feed";
JSONParser jParser = new JSONParser();
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("access_token", "**|*****"));
params.add(new BasicNameValuePair("client_id", "***"));
params.add(new BasicNameValuePair("client_secret", "****"));
JSONObject json = jParser.makeHttpRequest(url, "GET", params);
JSONArray data = json.getJSONArray("data");
Another way to fix it, which you should probably do anyway, is to make sure that params
has anything in it prior to processing it in your JSONParser
code: 修复它的另一种方法,您可能仍然应该这样做,是在使用
JSONParser
代码处理它之前,确保params
包含任何内容:
static InputStream is = null;
DefaultHttpClient httpClient = new DefaultHttpClient();
if (params != null && params.size() > 0){
String paramString = URLEncodedUtils.format(params, "utf-8");
url += "?" + paramString;
}
HttpGet httpGet = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
https://www.google.com/search?q=valid+url+characters -- do you see anything unusual around character 77? https://www.google.com/search?q=valid+url+字符-您发现字符77周围有什么异常之处吗? Also, https://www.google.com/search?q=encode+url
另外, https://www.google.com/search?q = encode + url
BTW, editing a question doesn't remove a previous revision: https://stackoverflow.com/posts/30601529/revisions 顺便说一句,编辑问题不会删除以前的修订: https : //stackoverflow.com/posts/30601529/revisions
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.