I am trying to read data from the file which is in Russian, eclipse gives a log of cracks, first the file is in windows-1251
, everything is fine, I convert it via notepad++
to UTF8
it does not read at all
Error parsing data org.json.JSONException: Value of type java.lang.String cannot be converted to JSONObject
but actually I am trying to read the file
public void addDataToDB() { try { InputStream is = getAssets().open("data.json"); int size = is.available(); byte[] buffer = new byte[size]; is.read(buffer); is.close(); String str = new String(buffer); parseJson(str); } catch (Exception ex) { Log.d("", "Error, wtf?"); } }
And it’s impossible to get normal Russian text from a file.
Well, I read Json like this
public void parseJson(String result) { try { JSONObject json = new JSONObject(result); JSONArray json_data = json.getJSONArray("data"); for (int i = 0; i < json_data.length(); i++) { JSONObject data = json_data.getJSONObject(i); Log.d("", data.getString("name")); ManController.write(getBaseContext(), "'" + data.getString("name") + "'", "'" + data.getString("barcode") + "'"); } } catch (JSONException e) { Log.e("log_tag", "Error parsing data " + e.toString()); } }