Search code examples
androidjsonparsingjsonexception

JSON Parsing Exception in Android


I have the following problem: I have a JSON File on a Server which I try to parse in Android. But i get the following error message:

06-13 19:24:39.025: E/JSON Parser(17169): Error parsing data org.json.JSONException: Value  of type java.lang.String cannot be converted to JSONObject

Here is my JSON File:

    {
"settings":[
  {
     "rss":"true",
     "rss_feed":"http://test.com/rss.rss"
  }
],
 "map_locations":[
  {
     "title":"Büro Toronto",
     "address":"123 Younge Street Toronto"
  },
  {
     "title":"Büro New York",
     "address":"Time Square New York"
  }
]
}

And this is my Code:

        JSONParser jParser = new JSONParser();

        JSONObject json = jParser.getJSONFromUrl(SETTINGS_URL);

        try {
            JSONObject c = json.getJSONArray("settings").getJSONObject(0);

            rss = c.getBoolean("rss");

            JSONArray jMap = json.getJSONArray("map_locations");
            for (int i = 0; i < jMap.length(); i++) {
                JSONObject c2 = jMap.getJSONObject(i);

                String map_title = c2.getString("title");
                String map_address = c2.getString("address");

                mapListTitle.add(map_title);
                mapListAddress.add(map_address);
            }

            URL_TO_RSSFEED = c.getString("rss_feed");
        } catch (JSONException e) {
            e.printStackTrace();
        } catch (NullPointerException e) {
            e.printStackTrace();
        }

Thanks for any help in advance!

The strange thing is that I didn't change anything (At my knowdledge) and it did work before. If you need any more information let me know!


Solution

  • Wow ok I found the answer... Had to change

    BufferedReader reader = new BufferedReader(new InputStreamReader(
                        is, "iso-8859-1"), 8);
    

    to

    to BufferedReader reader = new BufferedReader(new InputStreamReader(
                        is, "UTF-8"), 8);
    

    Strange enought it did work a few hours before with the same settings.

    But thanks alot for your help!