How can I parse JSON with comma in android?

Im trying to parse JSON and my code is not working with one URL and it works with other. I think its the coma in question but I did not sure so please look at my code and help. I tried to replace coma with dot in loop, but what i get is JSON Exception. And when I change the URL, there is no exception. Confusing… This is not working URL: And this is one I tested and it works: While changed the URL I also changed the data, so its not the problem in writing..I guess

Here is my code for coma replacement:

 private String convertStreamToString(InputStream is) {
 BufferedReader reader = new BufferedReader(new 
    StringBuilder sb = new StringBuilder();

    String line;
    try {
        while ((line = reader.readLine()) != null) {
            String coma = line.replaceFirst(",",".");
    } catch (IOException e) {
    } finally {
        try {
        } catch (IOException e) {

    return sb.toString();

And the other part with URL and JSONArray:

    protected Void doInBackground(Void... arg0) {
        URLconnection urlConn = new URLconnection();
        // Making a request to url and getting response
        String url = "";
        String response = urlConn.makeServiceCall(url);

        Log.e(TAG, "Response from url: " + response);
        if (response != null) {
            try {
                JSONObject jsonObj = new JSONObject(response);

                // Getting JSON Array node
                arr = jsonObj.getJSONArray("values");

                for (int i = 0; i < article.length(); i++) {

                    JSONObject c = arr.getJSONObject(i);
                    header = c.getString("Valuta");


            } catch (final JSONException e) {
                Log.e(TAG, "Json parsing error.");
                runOnUiThread(new Runnable() {
                    public void run() {
                                "Json parsing error: 216",


Commas aren’t the issue. It’s the very first character. One is a square bracket and the other is a curly one.

You therefore need to parse the first response as an Array rather than an Object

new JSONArray(response);

That being said, you therefore cannot use the same methods for both URLs

Leave a Reply

Your email address will not be published. Required fields are marked *