ciao!
da un servizio remoto, ottengo un json così:
del quale a me interessa principalmente il campo summary.codice:{ "index_searched": "isbn", "data": [ { "urls_text": "", "title": "Beginning iOS 5 Development", "marc_enc_level": "~", "awards_text": "", "dewey_decimal": "005", "subject_ids": [ "computers_technology_apple", "computers_technology_hardware_handheld_mobile_devices" ], "edition_info": "Paperback; 2011-12-07", "isbn13": "9781430236054", "physical_description_text": "7.5\"x9.2\"x1.9\"; 2.9 lb; 752 pages", "author_data": [ { "name": "Mark, David", "id": "mark_david" }, { "id": "nutting_jack", "name": "Nutting, Jack" }, { "name": "Jeff LaMarche", "id": "jeff_lamarche" } ], "publisher_id": "apress", "language": "", "lcc_number": "", "isbn10": "1430236051", "title_long": "Beginning iOS 5 Development: Exploring the iOS SDK", "book_id": "beginning_ios_5_development", "summary": "...............................", "publisher_name": "Apress", "publisher_text": "Apress", "notes": "", "title_latin": "Beginning iOS 5 Development", "dewey_normal": "5" } ] }
ho provato a farne il parsing così:
ma ottengo questa eccezione nel parsing della stringa JSON:codice:@Override protected Object doInBackground(Object... params) { try { JSONObject jsonObj = new JSONObject(s.launchIsbndb(intent.getStringExtra("isbn"))); JSONArray jsonArray = jsonObj.getJSONArray("data"); // Log.i("RES: ", jsonArray.getString(0)); for (int i = 0; i < jsonArray.length(); i++) { JSONObject c = jsonArray.getJSONObject(i); // Log.i("RES: ", c.getString("summary")); } } catch (IOException ex) { } catch (JSONException ex) { Log.i("JSONEX: ", ex.getMessage()); } return null; }
la richiesta che faccio è questa:codice:JSONEX: Expected ':' after r at character 6 of {r "data" : [r {r "title_latin" : "Beginning Python: From Novice to Professional, Second Edition",r "notes" : "",r "dewey_normal" : "5",r "title_long" : "Beginning Python: From Novice to Professional, Second Edition (Beginning from Novice to Professional)",r "lcc_number" : "",r "isbn10" : "1590599829",r "book_id" : "beginning_python_from_novice_to_professional_second_edition",r "publisher_text" : "Apress",r "publisher_name" : "Apress",r "summary" : ".........",r "isbn13" : "9781590599822",r "author_data" : [r {r "name" : "Magnus Lie Hetland",r "id" : "magnus_lie_hetland"r }r ],r "physical_description_text" : "6.9\"x9.2\"x1.5\"; 2.4 lb; 688 pages",r "publisher_id" : "apress",r "language" : "",r "urls_text" : "",r "marc_enc_level" : "~",r "title" : "Beginning Python: From Novice to Professional, Second Edition",r "dewey_decimal" : "005",r "subject_ids" : [r "computers_internet_programming_software_design_testing_engin",r "computers_internet_programming_languages_tools_python",r "computers_internet_programming_languages_tools_general",r "computers_internet_general"r ],r "awards_text" : "",r "edition_info" : "Paperback; 2008-09-08"r }r ],r "index_searched" : "isbn"r}r
ma non capisco tutte quelle r sparse qua e la.codice:public String launchIsbndb(String isbn) throws IOException { String stringUrl = "http://isbndb.com/api/v2/json/API_KEY/book/" + isbn.replaceAll("-", ""); URL url = new URL(stringUrl); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); InputStream is = connection.getInputStream(); BufferedReader rd = new BufferedReader(new InputStreamReader(is)); String line; StringBuilder response = new StringBuilder(); while ((line = rd.readLine()) != null) { response.append(line); response.append('r'); } rd.close(); return response.toString(); }
possibile un problema di encoding?

Rispondi quotando