java - Issue with conversion from XML to JSON with json or json-lib -


i having xml containing html content in node

<detail> &lt;p&gt;students should avoid purchasing textbooks @ first store browse. instead, should investigate alternatives offered other online booksellers. price isn't factor consider when making online purchase. students should factor in shipping costs , delivery time when making buying decision.&lt;/p&gt; </detail> 

while conversion xml json json or json-lib, by

import net.sf.json.json; import net.sf.json.xml.xmlserializer;  ..... jsonobject jsonobject = xml.tojsonobject(xml.tostring()); ...... 

xml string containing xml content

i should json string

{"detail":"&lt;p&gt;students should avoid purchasing textbooks @ first store browse. instead, should investigate alternatives offered other online booksellers. price isn't factor consider when making online purchase. students should factor in shipping costs , delivery time when making buying decision.&lt;/p&gt;"} 

but output

{"detail":{"p":"students should avoid purchasing textbooks @ first store browse. instead, should investigate alternatives offered other online booksellers. price isn't factor consider when making online purchase. students should factor in shipping costs , delivery time when making buying decision."}} 

which not proper.

can tell how can resolve issue?

try using library www.json.org instead of net.sf.json.json

import org.json.jsonobject; import org.json.xml;  string xmlstring = "<detail>&lt;p&gt;students should avoid purchasing textbooks @ first store browse. instead, should investigate alternatives offered other online booksellers. price isn't factor consider when making online purchase. students should factor in shipping costs , delivery time when making buying decision.&lt;/p&gt;</detail>"; system.out.println("initial xml : " + xmlstring); jsonobject jsonobj = (xml.tojsonobject(xmlstring)); system.out.println("converted json : " + jsonobj.tostring()); system.out.println("back converted xml : " + xml.tostring(jsonobj)); 

you'll result looks better mind :

initial xml : <detail>&lt;p&gt;students should avoid purchasing textbooks @ first store browse. instead, should investigate alternatives offered other online booksellers. price isn't factor consider when making online purchase. students should factor in shipping costs , delivery time when making buying decision.&lt;/p&gt;</detail> converted json : {"detail":"<p>students should avoid purchasing textbooks @ first store browse. instead, should investigate alternatives offered other online booksellers. price isn't factor consider when making online purchase. students should factor in shipping costs , delivery time when making buying decision.<\/p>"} converted xml : <detail>&lt;p&gt;students should avoid purchasing textbooks @ first store browse. instead, should investigate alternatives offered other online booksellers. price isn&apos;t factor consider when making online purchase. students should factor in shipping costs , delivery time when making buying decision.&lt;/p&gt;</detail> 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -