how to convert XML into a JSONObject

  • Lock & Lock

    Lock & Lock - 2007-01-30

    great project! I'm working with JSON, I need to convert XML into a JSONObject. Can you please, provide me with the sample code? Will that be a persistent JSONObject?

    • chaidb-admin

      chaidb-admin - 2007-01-30

      You should use XML.toJSONPObject method to convert the XML into an in-memory JSONObject. Then use one of the methods of JSONFactory class to persist this object. For example:

      JSONObject inMemory = XML.toJSONObject("<xml one = 1 two=' \&quot;2\&quot; '><five></five>First \u0009&lt;content&gt;<five></five> This is \&quot;content\&quot;. <three>  3  </three>JSON does not preserve the sequencing of elements and contents.<three>  III  </three>  <three>  T H R E E</three><four/>Content text is an implied structure in XML. <six content=\&quot;6\&quot;/>JSON does not have implied structure:<seven>7</seven>everything is explicit.<![CDATA[CDATA blocks<are><supported>!]]></xml>");
      JSONObject persistentOne = factory.getPersistentJSONObject("xmltest", inMemory.toString());


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks