c# - XML String to JSON using only native .NET methods -
i'm trying rewrite php function c#. php function converts xml string json.
at first, came this:
string[] zips = { "27249","27215"}; // request.form.get("zip").toarray(); list<string> listings = new list<string>(); var webclient = new webclient(); (int = 0; != zips.length; i++) { string returnxml = webclient.downloadstring("http://gateway.moviefone.com/movies/pox/closesttheaters.xml?zip=" + zips[i]); var json = new system.web.script.serialization.javascriptserializer().serialize(returnxml); listings.add(json); response.write(json); }
but output included encoded characters, wasn't wanted.
then, using json.net, replaced loop body this:
string returnxml = webclient.downloadstring("http://gateway.moviefone.com/movies/pox/closesttheaters.xml?zip=" + zips[i]); var xmldoc = new system.xml.xmldocument(); xmldoc.loadxml(returnxml); var json = jsonconvert.serializexmlnode(xmldoc); listings.add(json);
what bothers me thatthe conversion of xml string xmldocument can convert json string seems unnecessary. want json string later use in jquery function.
how can make first version work using intrinsic .net methods?
thanks.
i can't tell if there pre-made tool looking for, if looking squeeze every bit of performance conversion, can use jsonreader read json stream, , use xmlwriter output xml stream
with said, if json getting comes internet, unlikely going improve performance. introduce bugs. advice against that
Comments
Post a Comment