I have the following JSON:
{
"category": [{
"id": "90",
"user_id": "1",
"category_id": "27",
"name": "આણંદ કોમર્સિયલ લેયર",
"order": "0",
"created_at": "2014-05-03 17:09:54",
"updated_at": "2014-05-03 17:09:54",
"deleted": "0",
"subtopics": [{
"id": "203",
"user_id": "1",
"category_id": "27",
"subcategory_id": "90",
"name": "આણંદ કોમર્સિયલ લેયર (સંકર જાત)",
"order": "0",
"details": "<p style=\"text-align:justify\"><img alt=\"\" src=\"/packages/wysiwyg/ckeditor/plugins/kcfinder/upload/images/1.png\" style=\"height:271px; width:237px\" /></p>\r\n\r\n<ul>\r\n\t<li style=\"text-align:justify\">પ્રથમ ઈંડું મુક્વાની સરેરાશ ઉંમર:૧૪૨ દિવસ</li>\r\n\t<li style=\"text-align:justify\">સરેરાશ વાર્ષિક ઈંડા ઉત્પાદન : ૩૦૦ ઈંડા</li>\r\n\t<li style=\"text-align:justify\">૪૦ અઠવાડીયાની ઉંમરે ઈંડાનું સરેરાશ વજન : ૫૨ ગ્રામ</li>\r\n\t<li style=\"text-align:justify\">૭૨ અઠવાડીયાની ઉંમરે ઈંડાનું સરેરાશ વજન : ૫૪ ગ્રામ</li>\r\n\t<li style=\"text-align:justify\">સારી જીવાદોરી</li>\r\n</ul>\r\n",
"mobile_detail": "<p style=\"text-align:justify\"><img alt=\"\" src=\"/packages/wysiwyg/ckeditor/plugins/kcfinder/upload/images/1.png\" style=\"height:271px; width:237px\" /></p>\r\n\r\n<ul>\r\n\t<li style=\"text-align:justify\">પ્રથમ ઈંડું મુક્વાની સરેરાશ ઉંમર:૧૪૨ દિવસ</li>\r\n\t<li style=\"text-align:justify\">સરેરાશ વાર્ષિક ઈંડા ઉત્પાદન : ૩૦૦ ઈંડા</li>\r\n\t<li style=\"text-align:justify\">૪૦ અઠવાડીયાની ઉંમરે ઈંડાનું સરેરાશ વજન : ૫૨ ગ્રામ</li>\r\n\t<li style=\"text-align:justify\">૭૨ અઠવાડીયાની ઉંમરે ઈંડાનું સરેરાશ વજન : ૫૪ ગ્રામ</li>\r\n\t<li style=\"text-align:justify\">સારી જીવાદોરી</li>\r\n</ul>\r\n",
"created_at": "2014-05-03 17:11:43",
"updated_at": "2014-05-11 13:41:31",
"deleted": "0",
"images": [],
"videos": []
}]
}]
}
I have the following code:
public JSONObject getJSONFromUrl(String url) {
// Making HTTP request
InputStream is=null;
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
//HttpPost httpPost = new HttpPost(url);
HttpGet httpPost = new HttpGet(url);
httpPost.setHeader("Content-Type", "application/json");
httpPost.setHeader("X-Requested-With", "XMLHttpRequest");
httpPost.setHeader("Mobile-Tokon", "7c^4N:9Y*Tq;P^f");
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
String json="";
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 8000);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.toString();
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
// try parse the string to a JSON object
JSONObject jObj=null;
try {
jObj = new JSONObject(json);
Log.d("JSON",jObj.toString());
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
// return JSON String
return jObj;
}
In my Java class, I call the above function like this:
getJSONFromUrl("http://ikishan.192.168.1.87.xip.io/api/newapps/27?email=api.ikisan@aau.in&password=%~?7ON9Xjp;BcYu");
I get an error:
java.lang.IllegalArgumentException: Invalid % sequence: %~? in query at index 83: http://ikishan.192.168.1.87.xip.io/api/newapps/27?email=api.ikisan@aau.in&password=%~?7ON9Xjp;BcYu
At this line:
HttpGet httpPost = new HttpGet(url);
Any idea how I can solve this?
EDIT