JSON parser for Cocoa - objective-c

I'm starting with iOs. I'd like to know if there is a built-in JSON parser and , if not, what is the best alternative for mapping JSON string into Cocoa objects.
Thanks

If you are targeting iOS 5 only, then there is the built-in NSJSONSerialization class that will do the job nicely. If you need it to work in older versions of iOS, then something like SBJSON works well for me

There is a built in JSON parser (NSJSONSerialization) in iOS 5 and above.
If you want to target earlier versions of iOS, there are many third party ones such as TouchJSON.

Have you looked at JSONKit
JSONKit
JSONKit is dual licensed under either the terms of the BSD License, or alternatively under the terms of the Apache License, Version 2.0.
Copyright © 2011, John Engelhart.
A Very High Performance Objective-C JSON Library
UPDATE: (2011/12/18) The benchmarks below were performed before Apples NSJSONSerialization was available (as of Mac OS X 10.7 and iOS 5). The obvious question is: Which is faster, NSJSONSerialization or JSONKit? According to this site, JSONKit is faster than NSJSONSerialization. Some quick "back of the envelope" calculations using the numbers reported, JSONKit appears to be approximately 25% to 40% faster than NSJSONSerialization, which is pretty significant.

I use SBJson , it is not a built-in JSON parser, but I recommand it, you can try it.

Related

Processing JSON output in iOS

I made a very simple wordpress plugin that prints some posts in JSON format. I was wondering what is the best and simplest way is to process that information in Xcode.
I've seen many examples and many frameworks but I would like to hear your opinion and maybe some example code?
Thank you.
If you are targeting iOS 5.0 and later, the simplest way is using the NSJSONSerialization class that Apple provides.
As rob said if you're targeting iOS 5 use Apples NSJSONSerialization class. For earlier iOS versions there area also some options:
JSONKit (fastest)
SBJson
and others ...

What is the latest version of Objective-C?

Please can you tell me what is the last Objective-C version for now? and is there any official web-site for this language (like sunmicrosystems for JAVA) for which i can get information about this language?
The "official" Objective-C homepage is The Objective-C Programming Language, as pointed out in the objective-c tag info page.
The latest version of objective C is 2.0. I can't find any single website for the language, but Wikipedia article contains significant information with external links. The Objective-C Programming Language is considered the homepage for this language. You may also be interested in language variants section at Wikipedia. Please note that, though Obj-C 2.0 has garbage collector and iOS use Obj-C 2.0, it does not have GC.
Objective-C 2.0 was released in 2006, and, as of 2016, there is no 3.0. But that doesn't mean it hasn't changed.
You can find a list of the big Objective-C features supported by Xcode here. Sometimes detailed changes can be found in the Xcode release notes here. Other changes, like myobject->isa being replaced by object_getClass(myobject), are not advertised very well and you wind up discovering them through compiler warnings.
Five-year-old question, sure, but the answer constantly changes...
According to Apple's open-source web site, the version of Objective C 2.0 shipped with the latest version of OS X whose open-source components are available there (OS X 10.9.4 'Mavericks' as of this writing) is Objective-C 4, revision 551.1. (Feel free to leave a comment below if you can explain the discrepancy in Objective-C's version numbering between the documentation and the actual source code, would you?)
It's Objc4 now ! Objc source code here:
https://opensource.apple.com/tarballs/objc4/

How to get and parse JSON using objective C?

Is it possible to get and parse JSON using objective C, then manipulate it within the cocoa framework for the iphone/pad? I'm specifically looking to do this for a couple of public APIs out there.
See here: how to do json parsing in iphone
Basically, you should look into the TouchJSON library (with CJSONDeserializer and CJSONSerializer).
Used Json-framework on some previous projects, worked really well.
EDIT: I read your post a bit too fast. I've used it on a Mac app before but not targeting the iphone/ipad. I think it should work but have no background to it. Maybe someone else can confirm?
It's not only possible, it's dirt simple if you use one of the many existing open source projects dedicated to this task. I recommend trying yajl-objc, which offers a streaming parser, but json-framework is a good one too. They're very similar.
I'd stay away from TouchJSON, since it gave me trouble a while back with special characters (line breaks) in strings.
However, I'll join the choir recommending json-framework. Since I switched to that from TouchJSON everything's been running smoothly.
Regarding how to integrate the API in your project, they're equally simple to include and use.
As a side note, I'm just now testing out JSONKit, since it's supposed to be much faster than both TouchJSON and json-framework. However, I can't vouch for its stability yet. The reviews of it are good, though.
If you're developing an application that is only iOS 5.0 or later, you can use NSJSONSerialization.

Parsing and Writing XML in MAC 10.3.9 Cocoa?

What is the Best way i can do Parsing or Writing into XML using cocoa for mac10.3.9.?
Im mentioning the version of OS specifically because, i read in the documentation like, Mac 10.3.9 sdk does not support NSXML class.?
I Found an OpenSource libaray (libxml), is it the only library i can use????
Please give me some suggestion regarding the above....
Kindly reply Soon...
Thank you
Pradeep.
According to my copy of the documentation, the NSXMLParser class is available on Mac OS X 10.3 and later.
If for some reason you cannot use that, you can also use the Core Foundation XML Parser functions (search for CFXMLParser). This is a C-based API also developed by Apple. It will be deprecated in future versions of Mac OS X (after Snow Leopard), but since you're working on 10.3 that won't be a concern for you.
Many who cannot use those two also use libxml. Objective-C is able to use any C-based libraries with no penalty. I'm fairly certain Mac OS X ships with a copy of libxml you can link to (no need to download, build, or ship the library yourself; though if you want to, you certainly can).
What's best is going to depend on what features you need. Namespaces, for example, aren't fully supported by NSXMLParser in 10.3, but they are supported in 10.4.
Thanks for the replies....
I used libxml for xml parsing, it was working fine.
But still it has some problems like, even if the xml file is half consistent(i mean if the xml is corrupt, it loads the xml file).
libxml with xpath made things quite easy for xml parsing.

Cocoa/Objective-C - Can i somehow see the implementation files?

I believe i can learn thing or two if i can see the implementation files (.m files). Is there any way the i can view NSString.m or NSNumber.m files? and others? If i try to find these files using spotlight, i get nothing.
No, most (all?) of the Cocoa library implementations are only distributed in a compiled binary form. You could disassemble them, but that's probably against the Mac OS X EULA, and it also wouldn't help you understand them at all.
You could take a look at Cocotron, which is an open-source implementation of Cocoa. It won't be exactly the same, but at least for the core classes, it will be virtually identical.
Many of the basic cocoa classes, like NSString and NSNumber, are implemented in core foundation and "toll-free bridged" to objective-c classes. Core foundation is a C (not ObjC) API and the source is available as part of the Darwin open-source project.
So, to see how NSString or NSNumber is implemented under the hood, follow the link above and take a look at CFString and CFNumber, respectively (you'll need an Apple developer account, but registration is free).
Also worth looking at the mySTEP sources.
This helped me when doing something that subclassed NSMatrix some time ago.
I would guess they are already compiled into libraries.
I just did a quick check on my mac and could not find a NSString.m file as well. Are you utilizing Xcode's documentation? I find it has most everything I need.