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 by NSURLConnection. 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 see SBJsonStreamParser 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 the API 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 became SBJson.framework. On iOS libjson.a became libsbjson-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 requires Doxygen 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 the Classes 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
分享到:
相关推荐
9. **与其他库的比较**:NBJSON相对于其他JSON解析库(如SBJSON、NSJSONSerialization)来说,可能更轻量级,但功能同样强大,适合那些不希望引入大量依赖的项目。 通过理解和掌握NBJSON框架,iOS开发者能够更好地...
SBJSON包是iOS和Mac开发中广泛使用的第三方库,用于处理JSON(JavaScript Object Notation)数据的解析和编码。JSON是一种轻量级的数据交换格式,因其简洁和易于阅读的特性,被广泛应用于Web服务和应用程序之间的...
1. **SBJSON (json-framework)**:这是一个基于Objective-C的JSON解析库,由Stig Brautaset开发,提供快速且易于使用的JSON解析功能。 2. **TouchJSON (from touchcode)**:这是另一个Objective-C实现的JSON库,它...
- **手动导入**:将下载的`groopd-SBJSON-library-2cfbb4c`压缩包解压,将其中的SBJSON源代码文件拖入Xcode项目中。 7. **注意事项** - JSON字符串必须遵循JSON规范,否则解析会失败。 - 对于复杂的数据结构,...
SBJson 是 Objective-C 实现的一个 JSON 解析器和生成器.支持流, 格式友好的 JSON 输出 输出 JSON 的键是经过排序的 可配置的解析和输出的最大递归深度 纯 Objective-C. 无需第三方包依赖。
SBJson是Objective-C编写的JSON解析器,它提供了一套简单易用的API,帮助开发者轻松地进行JSON的编码和解码。 SBJson的主要功能包括: 1. **JSON编码(Encoding)**:将Objective-C对象编码为JSON字符串。例如,你...
SBJson是iOS平台上的一个流行JSON解析库,它为Objective-C开发者提供了方便、高效的API来处理JSON数据。 SBJson库由Stig Brautaset开发,它支持JSON的编码和解码功能,使得开发者可以轻松地将JSON字符串转换为...
SBJson是iOS和Mac开发中广泛使用的JSON解析库,它为Objective-C编程语言提供了一种高效、简单的方式来处理JSON(JavaScript Object Notation)数据。JSON是一种轻量级的数据交换格式,易于人阅读和编写,同时也易于...
1. SBJsonWriter.h:这是SBJSON库的JSON写入器头文件,提供了将Objective-C对象转换为JSON字符串的方法。通过`writeObject:`方法,开发者可以将字典、数组等可序列化对象转换成JSON格式的字符串,以便发送到服务器。...
本篇文章将详细介绍三种在iOS开发中常用的JSON解析库:SBJSON、TouchJSON以及JSONKit。 1. **SBJSON** SBJSON是Stig Brautaset开发的一个开源库,它提供了一个简单的方法来解析和生成JSON数据。SBJSON不仅支持...
SBJson 是 Objective-C 实现的一个 JSON 解析器和生成器,主要特性: 采用 New BSD 开源许可. 易用的 API 设计 支持流,详情请看 API docs 中的 SBJsonStreamParser 格式友好的 JSON 输出 输出 JSON 的键是经过排序...
"sbjson"是一个开源的JSON(JavaScript Object Notation)解析器和编码器,适用于Objective-C编程语言。这个资源包包含了所有你需要在你的iOS或Mac OS X应用中集成sbjson库的必要组件。以下是对sbjson及其相关知识点...
SBJson是iOS开发中常用的第三方JSON解析库,它由Stig Brautaset开发,提供了高效且易于使用的API来处理JSON(JavaScript Object Notation)数据。JSON是一种轻量级的数据交换格式,广泛应用于Web服务和移动应用的...
SBJSON是iOS和macOS平台上的一个开源JSON(JavaScript Object Notation)解析库,由Stig Brautaset开发。这个库被广泛使用,因为它提供了简单、高效的API,使得开发者能够快速地将JSON数据转换为Objective-C对象,...
本篇主要介绍如何在iPhone开发中进行JSON解析,结合给出的标签“源码”和“工具”,我们将深入探讨JSON解析的原理以及如何使用第三方库SBJSON进行操作。 一、JSON基础 JSON是一种轻量级的数据格式,它基于...
SBJson 5 在Objective-C中基于块的JSON解析和生成。 总览 SBJson的第一大功能是基于流/块的操作。... SBJson通过以下方式将JSON类型映射到Objective-C类型: JSON类型 Objective-C类型 空值 NSNul
本文将详细介绍四种常见的iOS JSON解析方式:TouchJSON、JSONKit、原生JSON以及SBJSON。 1. **TouchJSON** TouchJSON是早期流行的JSON库,它提供了简单的API来解析和生成JSON。使用TouchJSON,你可以通过`...
SBJSON是iOS开发中常用的第三方JSON解析库,它为Objective-C开发者提供了一种高效、简洁的方式来解析和生成JSON数据。JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,被广泛应用于网络通信,因为它...
以下是一个简单的使用SBJson解析JSON字符串的例子: ```swift import SBJson let jsonString = "{\"name\":\"John\", \"age\":30}" if let data = jsonString.data(using: .utf8) { if let jsonDict = try? JSON...
SBJSON是iOS和macOS平台上一个流行的JSON(JavaScript Object Notation)解析库,它由Stig Brautaset开发,提供了一套高效的API用于将JSON数据转换为Objective-C对象,反之亦然。在iOS开发中,处理JSON数据是常见的...