SBJson (aka json-framework)
来源:互联网 发布:c经典排序算法 编辑:程序博客网 时间:2024/05/02 00:11
SBJson (aka json-framework)
JSON (JavaScript Object Notation) is a light-weight data interchange format that's easy to read and write for humans and computers alike. This library implements strict JSON parsing and generation in Objective-C.
Notable changes in 3.1
Automatic Reference Counting (ARC) Support
Version 3.1 requires Xcode 4.2 to build, because previous versions did not have ARC support. If you can't use Xcode 4.2, or for some reason can't use ARC, you need to stick with SBJson version 3.0.
New Features, Changes, and Notable Enhancements in 3.0
JSON Stream Support
We now support parsing of documents split into several NSData chunks, like those returned byNSURLConnection. This means you can start parsing a JSON document before it is fully downloaded. Depending how you configure the delegates you can chose to have the entire document delivered to your process when it's finished parsing, or delivered bit-by-bit as records on a particular level finishes downloading. For more details seeSBJsonStreamParser and SBJsonStreamParserAdapter in the API docs.
There is also support for writing to JSON streams. This means you can write huge JSON documents to disk, or an HTTP destination, without having to hold the entire structure in memory. You can use this to generate a stream of tick data for a stock trading simulation, for example. For more information see SBJsonStreamWriter in theAPI docs.
Parse and write UTF8-encoded NSData
The internals of SBJsonParser and SBJsonWriter have been rewritten to be NSData based. It is no longer necessary to convert data returned by NSURLConnection into an NSString before feeding it to the parser. The old NSString-oriented API methods still exists, but now converts their inputs to NSData objects and delegates to the new methods.
Project renamed to SBJson
The project was renamed to avoid clashing with Apple's private JSON.framework. (And to make it easier to Google for.)
- If you copy the classes into your project then all you need to update is to change the header inclusion from
#import "JSON.h"
to#import "SBJson.h"
. - If you link to the library rather than copy the classes you have to change the library you link to. On the Mac
JSON.framework
becameSBJson.framework
. On iOSlibjson.a
becamelibsbjson-ios.a
. In both cases you now have to#import <SBJson/SBJson.h>
in your code.
API documentation integrated with Xcode
The InstallDocumentation.sh script allows you to generate API documentation from the source and install it into Xcode, so it's always at your fingertips. (This script requiresDoxygen to be installed.) After running the script from the top-level directory, open Xcode's documentation window and search for SBJson. (You might have to close and re-open Xcode for the changes to take effect.)
TweetStream Example Project
An example project showing how to use the new streaming functionality to interact with Twitter's multi-document streams. This also shows how to link to the iOS static lib rather than having to copy the classes into your project.
DisplayPretty Example Project
A small Mac example project showing how to link to an external JSON framework rather than copying the sources into your project. This is a fully functional (though simplistic) application that takes JSON input from a text field and presents it nicely formatted into another text field.
Features also present in previous versions
- BSD license.
- Super-simple high-level API: Calling
-JSONValue
on any NSString instance parses the JSON text in that string, and calling-JSONRepresentation
on any NSArray or NSDictionary returns an NSString with the JSON representation of the object. - The SBJsonParser and SBJsonWriter classes provides an object-oriented API providing a good balance between simplicity and flexibility.
- Configurable recursion depth limit for added security.
- Supports (but does not require) garbage collection.
- Sorted dictionary keys in JSON output.
- Pretty-printing of JSON output.
Installation
The simplest way to start using JSON in your application is to copy all the source files (the contents of theClasses
folder) into your own Xcode project.
- In the Finder, navigate to the
$PATH_TO_SBJSON/Classes
folder and select all the files. - Drag-and-drop them into your Xcode project.
- Tick the Copy items into destination group's folder option.
- Use
#import "SBJson.h"
in your source files.
That should be it. Now create that Twitter client!
Upgrading
If you're upgrading from a previous version, make sure you're deleting the old SBJson classes first, moving all the files to Trash.
Linking rather than copying
Copying the SBJson classes into your project isn't the only way to use this framework. With Xcode 4's workspaces it has become much simpler to link to dependant projects. The examples in the distribution link to the iOS library and Mac framework, respectively. Des Hartman wrote a blog post with step-by-step instructions for iOS.
Links
- GitHub project page
- Example Projects
- Online API docs
- Frequently Asked Questions
- SBJson (aka json-framework)
- 不要使用SBJSON(json-framework)
- 不要使用SBJSON(json-framework)
- 不要使用SBJSON(json-framework)
- 不要使用SBJSON(json-framework)
- 不要使用SBJSON(json-framework)
- 不要使用SBJson(json-framework)
- 不要使用SBJSON(json-framework)
- 不要使用SBJSON(json-framework)
- 不要使用SBJSON(json-framework)
- objective-c json处理 SBJson (Previously known as json-framework)
- 『IOS』不要使用SBJSON(json-framework)
- Parsing JSON With SBJSON
- iOS json解析之SBJson
- SBJson
- SBJson
- SBJson
- iOS 使用SBJSON创建和解析JSON
- 人为什么那么累
- HTTP Header 详解
- Shell脚本调试技术
- Android应用开发笔记
- MVC3中Action间传值
- SBJson (aka json-framework)
- BlueLab修改库文件方法
- JSON介绍
- android 画面横屏竖屏设置
- STL Sort算法
- 谓词使用
- 搜索引擎算法变化对于SEO的影响
- java设计模式--单例模式应用--02
- Naxsi is an open source, high performance, low rules maintenance, Web Application Firewall module fo