You are getting a single Json object from response. As {"Url":"www.google.com"}
is a JSONObject.
So the line
JSONArray json = jParser.getJSONFromUrl(url);
should be as
JSONObject json = jParser.getJSONFromUrl(url);
And while reading the data you only need
String json_url = json.getString(TAG_Url);
instead of using for loop.
See the updated class
public class JSONParser {
static InputStream is = null;
static String json = "";
JSONObject jsonObject = null; // Updated here
// konstruktor
public JSONParser() {
}
public JSONObject getJSONFromUrl(String url) {
jsonObject = null; // Updated here
// HTTP request
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
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();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
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());
}
// json array paser til string
try {
jsonObject = new JSONObject(json); // Updated here
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
// retunerer json object tilbage
return jsonObject; // Updated here
}
}
This will work for your current json. See // Updated here
to know what I have updated.