Skip to content

XML.toJSONObject() crashes if CDATA is part of XML #287

Closed

Description

@AppWerft

in relation to:
http://stackoverflow.com/questions/29283261/converting-xml-to-json-android

I have the same issue too ans ask me, why "No virtual method end()Z in class Lorg/json/XMLTokener".

Any ideas?

Activity

  1. stleary commented on Sep 21, 2016

    @stleary
    Owner

    Thanks! Will investigate as soon as possible.

  2. johnjaylward commented on Sep 21, 2016

    @johnjaylward
    Contributor

    This looks like another classpath issue. Method end()Z (end method that returns boolean) is defined in the JSONTokener class, which XMLTokener extends.

    @AppWerft , are you sure you've included all the classes in the json-java project at runtime? Also, where did you get your copy from?

  3. stleary commented on Sep 22, 2016

    @stleary
    Owner

    The latest JSON-Java code is able to parse the sample XML in the StackOverflow page, with CDATA included. Was also able to execute successfully using the following Maven Central Repository releases:
    20160810
    20160807
    20160212
    20151123
    20150729
    20141113
    20140107
    20131018
    Earlier than that, the parser starts throwing exceptions, but not from the CDATA. Recommend that you try a later build and let us know if the problem persists:
    http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.json%22%20AND%20a%3A%22json%22

  4. AppWerft commented on Sep 22, 2016

    @AppWerft
    Author

    Thank you. Now I have used the newest version.
    At runtime:

    [ERROR] :  AsyncHttpRH: User-space exception detected!
    [ERROR] :  AsyncHttpRH: java.lang.NoSuchMethodError: No static method stringToValue(Ljava/lang/String;)Ljava/lang/Object; in class Lorg/json/JSONObject; or its super classes (declaration of 'org.json.JSONObject' appears in /system/framework/core-libart.jar)
    

    My thoughts:
    in buildpath is android.jar from sdk23 too (on start of list). This version don't know this method 'stringToValue()'. How can I solve? I build with ant.

  5. AppWerft commented on Sep 22, 2016

    @AppWerft
    Author

    Now I have refactored your package to org.json.jsonjava and all is fine. Is there a reason to use the same package name?

  6. stleary commented on Sep 22, 2016

    @stleary
    Owner

    Unless @johnjaylward has additional comments, suggest you send us enough information about your devekopment environment, such that we can try to recreate the problem.

  7. johnjaylward commented on Sep 22, 2016

    @johnjaylward
    Contributor

    @AppWerft, it appears to be a configuration issue with how you are building your application. If you can post your ant build file that would be a helpful start.

  8. AppWerft commented on Sep 23, 2016

    @AppWerft
    Author

    My problem is: the result of XML.toJSONObject() generates a construct of JSONObject/JSONArray. This parts are from your lib and not from org.json. I'm working with Appcelerator Titanium and the framework tries to convert to javascript layer and aspects that this is from org.json. Therefore I run in an error. If your lib would extends the original org.json (and not "overwrite" with same package name/classnames) then it would works. Currently I return a stringify version of result and parse on JS layer.

  9. AppWerft commented on Sep 23, 2016

    @AppWerft
    Author
  10. stleary commented on Sep 23, 2016

    @stleary
    Owner

    No objection if you want to propose a pull request to enhance toMap().

  11. AppWerft commented on Sep 23, 2016

    @AppWerft
    Author

    Hi, I have modified and now it runs.

    1. I have renamed the package org.json into org.json.jsonjava to avoid conflicts.
      2, I have rewrite toMap() https://github.com/AppWerft/Ti.RemoteXML/blob/master/android/src/de/appwerft/remotexml/JSON.java
  12. AppWerft commented on Sep 23, 2016

    @AppWerft
    Author
  13. johnjaylward commented on Sep 23, 2016

    @johnjaylward
    Contributor

    @AppWerft can you post a non-compressed version?

  14. johnjaylward commented on Sep 23, 2016

    @johnjaylward
    Contributor

    @AppWerft it looks like you are trying to use 2 different versions of the JsonJava code, one of which you repackaged as or.json.jsonjava

    I'm not able to understand why you would do this. Is there some reason you need to include 2 different versions?

  15. AppWerft commented on Sep 23, 2016

    @AppWerft
    Author

    here is it

    Am 23/09/16 um 20:00 schrieb johnjaylward:

    @AppWerft https://github.com/AppWerft can you post a non-compressed
    version?

    —
    You are receiving this because you were mentioned.
    Reply to this email directly, view it on GitHub
    #287 (comment),
    or mute the thread
    https://github.com/notifications/unsubscribe-auth/AC24DStv66x36M9Dm4xT6rCEj57Vnw5nks5qtBO6gaJpZM4KDJEC.

    Dipl.-Ing. Rainer Schleevoigt
    Certified TYPO3 Integrator
    Certified Titanium App Developer

    Novalisweg 10
    

    22303 Hamburg
    ℡ 040 60812460
    |Ust-ID: DE239491976|||||||

  16. 11 remaining items

  17. AppWerft commented on Sep 24, 2016

    @AppWerft
    Author

    You make a new class JSONObjectPlus. This class extends JSONObject. In this case you need i.e only to add StringtoValue() to this class and you avoid evil copy processes.

  18. AppWerft commented on Sep 24, 2016

    @AppWerft
    Author
    package org. stleary.json;
    import org.json.*
    
    class JSONObjectPlus extends JSONObject {
         public Object StringtoValue(String foo) {
           /// some stuff
         return object;
       }
    }
  19. stleary commented on Sep 24, 2016

    @stleary
    Owner

    Refactoring the JSON-Java org.json package name is not an option at this time. No objection to other reasonable actions to help the Android devs, which can be posted here. This issue will be left open for a few days in case of comment. The Wiki will be updated with a section on the issues facing Android devs.

  20. stleary commented on Sep 25, 2016

    @stleary
    Owner

    https://github.com/stleary/JSON-java/wiki/JSON-Java-for-Android-developers

    The Wiki page is currently open for anyone to make changes, if you want to add new information or edit what is already there.

  21. stleary commented on Sep 28, 2016

    @stleary
    Owner

    If someone wants to start a project that contains only the minimal changes to JSON-Java needed for Android support, links can be added from this Readme and Wiki. Otherwise, please post here of any changes you think are necessary.

  22. AppWerft commented on Sep 28, 2016

    @AppWerft
    Author

    I will do. I have built a special exporter. It works fine. Currently I'm testing against: all links inside http://www.openarchives.org/pmh/registry/ListFriends

  23. stleary commented on Oct 15, 2016

    @stleary
    Owner

    Any updates on your exporter, @AppWerft?

  24. AppWerft commented on Oct 15, 2016

    @AppWerft
    Author
  25. stleary commented on Nov 19, 2016

    @stleary
    Owner

    I don't think we have a 3rd party solution that we can point Android devs to (but correct me if I am wrong). Ideally, this this problem should be fixed in the Android project. Does anyone want to drive this? Otherwise, is there anything we can do to make the XML code Android friendly, without affecting our own users?

  26. quelgar commented on Dec 22, 2016

    @quelgar

    FYI I hit this due to a library called Easy JSON being on the classpath. It has its own version of org.json.JSONTokener.

  27. stleary commented on Dec 23, 2016

    @stleary
    Owner

    @quelgar does EasyJSON have some functionality that is missing from this project?

  28. quelgar commented on Dec 24, 2016

    @quelgar

    @stleary no, I don't think so. I don't actually know why it's included by the app, I was just called in to troubleshoot the weird error. It looked to me like a really really old version of your library was embedded inside the Easy JSON jar. Nothing you can really do to avoid it, but at least this ticket can document the possible reasons for this error.

  29. johnjaylward commented on Jun 21, 2017

    @johnjaylward
    Contributor

    see #350

  30. stleary commented on Jan 13, 2018

    @stleary
    Owner

    This issue has been addressed to the extent that we can from this side. For more information please see the wiki page: https://github.com/stleary/JSON-java/wiki/JSON-Java-for-Android-developers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions