tags:

views:

224

answers:

2

Does anyone know of a library that will convert XML to JSON in objective C (on the iPhone)?

Thanks in advance,

Rob

A: 

I know it's not exactly what you want, but here is an article for a JSON library on the iPhone.

http://iphonedevelopertips.com/cocoa/json-framework-for-iphone-part-2.html

Combine that with this tutorial on reading XML on the iPhone and with a little elbow grease, you can create your own xml to JSON converter. As I said, not exactly what you wanted, but I hope it helps.

http://www.iphonesdkarticles.com/2008/11/parsing-xml-files.html

chamiltongt
A: 

Is there a particular reason why you require XML converted to JSON?

At the end of the day, they both represent the same data - and I assume the data is what is important here.

If you have data represented in XML that needs to be posted to a server that only accepts JSON, then I understand why you'd need a converter, but consider this first:

Parse the XML into native Foundation objects (NSDictionary, NSArray, NSString, NSNumber, etc.). Then use a JSON library such as JSON-Framework to write the Foundation objects into a JSON representation.

The same could be done if downloading XML. Although if you're downloading XML, I don't understand why you'd need to convert it into JSON before parsing it?

Jasarien
Not required, but the XML is pretty intricate, I was hoping not to have to have the parser keep track of all of the various levels when reading it in, reading into JSON is sooooo much easier to work with.
Rob Bonner
The data represented by the XML should be the same structure whether its in XML or JSON... if you parse the XML into foundation objects, the result will be the same as if you parse JSON into foundation objects....
Jasarien