Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. //Jsp (server)
  2.  
  3. String xCatalogo = request.getParameter("xCatalogo");
  4. String xdburl = request.getParameter("xUrl");
  5. String xdbuser = request.getParameter("xUser");
  6. String xdbpass = request.getParameter("xPass");
  7. conexion con = new conexion(xdburl, xdbuser, xdbpass);
  8. ResultSet rs1;
  9. int xResultado = 0;
  10. JSONObject json = new JSONObject();
  11. String qry = "";
  12. String whtml2 = "";
  13. // ArrayList<String> catalog = new ArrayList<String>();
  14. if (xCatalogo.equals("cFrigorificos")) {
  15. qry = "select * from tcatfrigo where icatfrigostatus=1 order by icatfrigoorden";
  16. rs1 = con.consulta(qry);
  17. List<catFrigorifico> listacatFrigorificos = new ArrayList<catFrigorifico>();
  18. if (rs1.next()) {
  19. xResultado = 1;
  20. rs1.beforeFirst();
  21. while (rs1.next()) {
  22. catFrigorifico xFrigo = new catFrigorifico(rs1.getInt("icatfrigoid"), rs1.getString("ccatfrigocodigo"), rs1.getString("ccatfrigonombre"), rs1.getInt("icatfrigoorden"));
  23. listacatFrigorificos.add(xFrigo);
  24. // catalog.add(rs1.getInt("icatfrigoid") + "|" + rs1.getString("ccatfrigocodigo") + "|" + rs1.getString("ccatfrigonombre") + "|" + rs1.getInt("icatfrigoorden"));
  25. }
  26. }
  27. // json.put("xListaCatalogosFrigorificos", catalog);
  28. json.put("xListaCatalogosFrigorificos", listacatFrigorificos);
  29. }
  30. json.put("xResultado", xResultado);
  31. out.println(json);
  32. out.flush();
  33.  
  34. //Android (client)
  35. try {
  36. //Creating JsonObject from response String
  37. JSONObject jsonObject = new JSONObject(response.toString());
  38. Log.v("JSONParser", "response: " + response.toString());
  39. //extracting json array from response string
  40. JSONArray jsonArray = jsonObject.getJSONArray("xListaCatalogosFrigorificos");
  41. for (int i=0; i<jsonArray.length(); i++){
  42. JSONObject json_data = jsonArray.getJSONObject(i);
  43. json_data = json_data;
  44. }
  45. } catch (JSONException e) {
  46. Log.i("tag", "error Json " + e.getMessage());
  47. }
  48.  
  49.  
  50. the problem is in Android Part in this line:
  51. JSONObject json_data = jsonArray.getJSONObject(i);
  52.  
  53. throw a exception and is:
  54. "Value beans.catFrigorifico@15aa13f7 at 0 of type java.lang.String cannot be converted to JSONObject"
  55.  
  56. how to fix?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement