Loading ...
Sorry, an error occurred while loading the content.

124Re: [json] Re: first time using JSON, servlet throws exception

Expand Messages
  • James Black
    Nov 30, 2005
      Hash: SHA1

      Martin Cooper wrote:
      > On 11/30/05, James <jblack@...> wrote:
      >> --- In json@yahoogroups.com, MPCM <WickedLogic@g...> wrote:
      >> >
      >> > Looks like you need comma between your array values (objects in your
      >> case);
      >> Thank you for the response. Now I have modified my array, and am now
      >> having a different problem.
      >> Here is my java code:
      >> temparray = jsonarray.getJSONArray(t);
      >> System.out.println(temparray);
      >> cntr = temparray.getInt(0);
      >> grade[t] = temparray.getString(1);
      >> pidm[t] = bean.getBean()[cntr].getPidm();
      >> lastAttenddate[t] = temparray.getString(2);
      >> I get an error on temparray.getInt(0) with, JSONObject[0] is not a
      >> number.
      >> When I had temparray.getString(1) first the error was:
      >> NoSuchElementException: JSONArray[1] not found.
      >> temparray = [{"cntr": 1, "grade": "C", "lastdateattended": ""}]
      > This is an array with a single element, and that element is an object. Your
      > original array, after you fixed the commas, was an array of objects. It
      > looks like you are trying to treat the objects as if they are arrays, which
      > they are not.

      Thank you for the response. I will look at it tomorrow to see if
      trying to pull the values out as a JSONObject will work.

      If I want it to be an array, would I have:
      temparray = [[{"cntr": 1}],[{"grade": "C"}],[{"lastdateattended": ""}]]

      Would this be an array, where my java function would work?

      If it doesn't work then I may have to just use the String functions to
      pull out my values, on the java side; but I would prefer to use the json

      - --
      Corruptisima republica plurimae leges. [The more corrupt a republic, the
      more laws.]
      Tacitus from Annals III, 116AD
      -----BEGIN PGP SIGNATURE-----
      Version: GnuPG v1.4.0 (MingW32)

      -----END PGP SIGNATURE-----
    • Show all 7 messages in this topic