Results 1 to 4 of 4
  1. #1
    DigitalMan is offline Member
    Join Date
    Jan 2010
    Posts
    10
    Rep Power
    0

    Default Put JSONObject to JSONArray?

    I have a need to put() a JSONObject into a JSONArray. For some reason, it seems no one's attempted this in Java, so I'm having trouble finding an answer. It's possible to directly retrieve a JSONObject from a JSONArray - the inability to go the other way around seems like a major oversight. Am I overlooking something?

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    Uhm, what is wrong with this method?
    Java Code:
    public JSONArray put(java.lang.Object value)
    or this method?
    Java Code:
    public JSONArray put(int index, java.lang.Object value)

  3. #3
    DigitalMan is offline Member
    Join Date
    Jan 2010
    Posts
    10
    Rep Power
    0

    Default

    It refuses to accept a JSONObject. Even one that has just been extracted from another JSONArray, without anything done to it. Any other type of object works fine. And I can absolutely confirm that both JSONObjects and JSONArrays work as expected otherwise, as this program has been running on them for quite some time.

    However, I'm working on a solution... that involves creating my own JSON parser. I'm rather sick of distributing 1.3MB worth of jars in 6 files with my under-100KB program.

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    What is the error it gives?

    The only think I can think of, though, is that they have placed a check at the beginning of those methods to check whether it is a JSONObject and refuse it if it is. So, in that case, you will have to ask the developers of the library.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •