简体   繁体   English

java.lang.IllegalArgumentException:Android中索引77的查询中的非法字符

[英]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.

相关问题 引起:java.lang.IllegalArgumentException:索引 120 处查询中的非法字符 - Caused by: java.lang.IllegalArgumentException: Illegal character in query at index 120 原因:java.lang.IllegalArgumentException:索引72的查询中的非法字符 - Caused by: java.lang.IllegalArgumentException: Illegal character in query at index 72 java.lang.IllegalArgumentException:索引59处查询中的非法字符 - java.lang.IllegalArgumentException: Illegal character in query at index 59 http连接中的错误java.lang.IllegalArgumentException:索引76处的查询中的非法字符 - Error in http connection java.lang.IllegalArgumentException: Illegal character in query at index 76 java.lang.IllegalArgumentException:方案中索引0处的非法字符: - java.lang.IllegalArgumentException: Illegal character in scheme at index 0: java.lang.IllegalArgumentException:索引 0 处方案中的非法字符:localhost - java.lang.IllegalArgumentException: Illegal character in scheme at index 0: localhost java.lang.IllegalArgumentException:&#39;不是有效的XML字符 - java.lang.IllegalArgumentException : ' is not a valid XML character java.lang.IllegalArgumentException:找不到命名查询: - java.lang.IllegalArgumentException: Named query not found: java.lang.illegalargumentexception 没有为该名称定义查询 [...] - java.lang.illegalargumentexception no query defined for that name [...] 对bean的Solr查询 - java.lang.IllegalArgumentException - Solr query to beans - java.lang.IllegalArgumentException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM