java - Issue with conversion from XML to JSON with json or json-lib -
i having xml containing html content in node
<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> </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":"<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>"}
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><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></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><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></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><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></detail>
Comments
Post a Comment