ciao!
sto cercando di leggere dei dati in JSON in una servlet.
questi stessi identici dati li uso anche in una appa per android senza problemi.
nella servlet ho messo questo:
codice:
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String strUrl = "...............";
BufferedReader buff = new BufferedReader(new InputStreamReader(new URL(strUrl).openStream()));
StringBuilder sb = new StringBuilder();
String str;
while ((str = buff.readLine()) != null) {
sb.append(str).append("\n");
}
String strJson = sb.toString();
try {
JSONObject jObj = new JSONObject(strJson);
resp.getWriter().println(jObj.get("nome"));
} catch (JSONException e) {
resp.getWriter().println(e.getMessage());
}
}
ma ottengo questo errore:
codice:
A JSONObject text must begin with '{' at character 1 of [{"id":"35","nome":"abbonamenti riviste"},....................
l'erroe è comprensibile, ma mi chiedo perchè su android non ho problemi.
anche la ho usato JSONObject.