Note that there are some explanatory texts on larger screens.

plurals
  1. POJava String conversion to JSON can not be done
    primarykey
    data
    text
    <p>I have JSON which I get from server:</p> <pre><code> "[{\"id\":\"1\",\"name\":\"Milos\",\"city\":\"Smederevo\",\"email\":\"milos\",\"password\":\"\"}, {\"id\":\"3\",\"name\":\"Boban\",\"city\":\"Beograd\",\"email\":\"bole\",\"password\":\"\"}, {\"id\":\"4\",\"name\":\"Pele\",\"city\":\"Brazil\",\"email\":\"pele@pele.com\",\"password\":\"\"}, {\"id\":\"5\",\"name\":\"admin\",\"city\":\"Smederevo\",\"email\":\"admin\",\"password\":\"\"}]" </code></pre> <p>I am using that json and sending to my thread (android thread):</p> <pre><code> try { // Method from which I am getting Json described above String s = dm.getAllUsers(); /*JSONParser jp = new JSONParser(); JsonElement jelement = new JsonParser().parse(s); JsonArray array1 = jelement.getAsJsonArray();*/ JSONArray array = new JSONArray(s); for (int i = 0; i &lt; array.length(); i++) { JSONObject menuObject = array.getJSONObject(i); // doing something with the object } } catch (JSONException e) { e.printStackTrace(); } </code></pre> <p>I can not process that Json at all. I am getting the error "java.lang.String cannot be converted to JSONArray". A know that problem is caused by "\", and I just do not know how to get rid of "\".</p> <p>I tried:</p> <pre><code>1) s.replace("\\", ""); 2) s.replace("\"", "'"); 3) s.replaceAll("\\", ""); 4) s.replaceAll("\"", "'"); </code></pre> <p>In order to erase "\" but replace do not react at all. I also tried to solve problem with "google-gson-2.2.2" library (code under the comment above, under the method).</p> <p>Any advice, please?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload