iPhone : Which parsing method is best to use? - iphone

i want to know which parsing method is best to use among
Simple XML parsing
JSON Parsing.
i am new to iPhone programming...thats why i want to know
what is the advantages of JSON parsing ?
when to use JSON Parsing ?
thanking in advance...

Since you are asking about which parsing method to use, the answer would simply be "one that match your data". JSON and XML does not use the same schemas, so you would not be able to choose freely.
On the other hand if you are actually asking which data format to use, then I'll suggest having a look at this post.

Related

iPhone : Which type of parser recommended for data parsing between iPhone and web-service?

Can any body tell me which parser is best in my condition? XML, JSON or any else ?
The app contains feature link sync the data, communicate with the web-service and etc. So I am targeting parser which is light weight and fast.
I have lots of data which are parsed between iPhone and server.
Which are the option? Or any good link for comparison between different parser ?
I would suggest JSON as in terms of data size json tends to be compact compared to XML. Which will reduce time spent in network transfer (for your data).
You could use any available JSON parsers to directly get ObjectiveC objects. Some Json parsers -
NSJSONSerialization
json framework
jsonKit
I personally prefer jsonKit as its supposed to be fastest of all.
Of course it's JSON.
This is the frequent question asked on stack.You could find much better answer just by Goggling.
JSON has several advantages over XML. Its a lot smaller and less bloated, so you will be passing much less data over the network - which in the case of a mobile device will make a considerable difference.
Refer to JSON Tutorial for iPhone.
Mr.Devang. I recommend NSXMLParser. If your data or response from service will be in XML format please use NSXMLParser. Apple have inbuilt xml parsing tool. Please refere Apple document fir NSXMLParser,
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSXMLParser_Class/Reference/Reference.html
http://developer.apple.com/library/mac/#documentation/cocoa/reference/NSXMLParserDelegate_Protocol/Reference/Reference.html
And also, if you receive your web-service response in JSON format, you can use SBJSON to parse the JSON files. You can get the json framework form this link,
https://github.com/stig/json-framework/
Thanks.
If you would like to know about different XML Parsers available and comparison between them, you can visit this tutorial which shows different xml parsers available and comparison between them.

Parsing large quantities of JSON data in iOS

I'm getting a large JSON string (11MB) from a web service. When I parse the data using JSONKit, my app reaches 70MB, I get memory warnings, and the app crashes.
How can I parse this data?
the easiest solution is reducing the json size you are getting from the server. If you cant to it, the only way to parse huge JSON is using lazy evaluation.
I dont think there is a JSON lib for objective-c that supports lazy evaluation. however you can implement one.
Your best bet is to look at the YAJL JSON parser, that supports event driven parsing. Then you can parse the JSON as it comes down in a data feed, and not have to store the whole thing in memory at once.
https://github.com/gabriel/yajl-objc
Sorry, I don't know of any code examples that demonstrate this use in practice.
SBJson supports parsing a stream of data. This lets your process your document bit by bit so you don't need to hold on to the entire document. The distribution contains two examples of how to use this. First there's the StreamParserIntegrationTest.m and next there's the TweetStream demo app: a twitter application that will sit and parse a HTTP stream all day (if you let it) displaying each tweet as they come in and then throw them away.
(Disclaimer: I am SBJson's author.)
11 mb is a largedata and solution is only to minimise your size of data
JSON support is not native to iOS, but there is a great framework for this exact purpose: http://code.google.com/p/json-framework/
This framework supports conversion from raw JSON objects to Objective-C objects (NSArray, NSDictionary) and vice versa.

iPhone xml parsing/editing a better solution?

I use GDataXML for parsing the XML I received from my webservice, actually I only parse the part that I need and then I want to "edit" that XML and send it back to Webservice.
I checked some GDataXML examples but they were about saving XML as model objects and creating an XML from model objects again.
Because speed is important what I want is without saving or converting that xml into model objects I just want to edit/delete some nodes on it and send it back quickly as possible.
Actually I can do this by simply converting it into string and do string manipulation. But I dont think editing XML as a string is a safe way.
How can I do this better?
Thanks
I tend to use a XML to NSDictionary object that I found on google which saves a lot of time parsing and configuring the XML. Try that out.

What's the best way to parse XML from a URL for iOS?

I'm looking for the best way to parse XML on iOS. There seem to be SO many ways to do this, so many different examples. Specifically, I want to send a request to a weather service, then extract the weather from the XML response.
If you could point me in the right direction and hopefully someone else will also find this useful.
If the xml document is small to medium sized, then NSXMLParser is the way to go: NSXMLParser
Check out this one - How To Choose The Best XML Parser for Your iPhone Project

Saving and Editing JSON on iPhone/iPod

What's the best method for editing and saving a JSON file on the iPhone/iPod? I know there are libraries that allow you to easily read JSON data, but are there any that allow you to generate it?
TouchJSON reads and generates JSON, is quite fast, and uses very little memory.
JSON Framework is supposedly faster, but uses much more memory.
The iPhone also includes a built-in JSON parser/generator, but it's only available through private APIs. You probably shouldn't use this one.
TouchJSON allows conversion both to and from JSON with a single call like:
[[CJSONSerializer serializer] serializeObject:someDictionaryofYours];