Visualizzazione dei risultati da 1 a 5 su 5
  1. #1

    Problem,a con servlet e JSON

    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.

  2. #2
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    55
    Quale JSONObject hai importato?

  3. #3
    Utente di HTML.it L'avatar di neroux
    Registrato dal
    Aug 2009
    Messaggi
    1,973
    Pare che vuoi leggere un oggetto mentre la stringa contiene un json array. Potrebbe essere una versione diversa della classe?

    www.sitemeer.com » Quando un sito pare irraggiungibile

    Se ti piace ci puoi trovare anche su Facebook

  4. #4
    eh si non ci avevo fatto caso:
    codice:
    import com.google.appengine.labs.repackaged.org.json.JSONObject;
    probabilmente è questo che da fastidio.

  5. #5
    ho scaricato la libreria org.json e l'ho inclusa nel progetto (con eclipse).

    dentro il war (e nella directory lib) vedo il jar.

    non ho errori in compilazione, ma ho questo errore in esecuzione:
    codice:
    HTTP ERROR 500
    
    Problem accessing /json. Reason:
    
        org/json/JSONException
    
    Caused by:
    
    java.lang.NoClassDefFoundError: org/json/JSONException
    .......................................
    Caused by: java.lang.ClassNotFoundException: org.json.JSONException
    ................................

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.