SBJson (aka json-framework)

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.

  1. In the Finder, navigate to the $PATH_TO_SBJSON/Classes folder and select all the files.
  2. Drag-and-drop them into your Xcode project.
  3. Tick the Copy items into destination group's folder option.
  4. 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

时间: 2024-10-06 23:56:49

SBJson (aka json-framework)的相关文章

ios关于不会用sbjson创建json,请教

问题描述 ios关于不会用sbjson创建json,请教 请问这种形式的json怎么创建 ,在下新手请给demo事例 ,项目中有sbjson库 {"code":"1","desc":[{"col_0007":"李玉华", "col_0023":"已回单","col_0025":"800.00", "col_0027&q

ios-解析(__NSArrayM objectForKey:)出现问题

问题描述 解析(__NSArrayM objectForKey:)出现问题 在用SBJson解析Json的时候出现问题,总是得到错误:"__NSArrayM objectForKey:" 要解析的Json: { "result": [ { "authors": [ "Eric Ries" ], "bc": 9780671607, "title": "Yeah", &q

【转载】GitHub Top 100 简介(IOS框架)

GitHub Top 100 简介 主要对当前 GitHub 排名前 100 的项目做一个简单的简介, 方便初学者快速了解到当前 Objective-C 在 GitHub 的情况.              原文链接:https://github.com/Aufree/trip-to-iOS/blob/master/Top-100.md Android 版本的在此: https://github.com/Freelander/Android_Data/blob/master/Android-Li

iOS GitHub Top 100 简介

主要对当前 GitHub 排名前 100 的项目做一个简单的简介, 方便初学者快速了解到当前 Objective-C 在 GitHub 的情况. 项目名称 项目信息 1. AFNetworking 作者是 NSHipster 的博主, iOS 开发界的大神级人物, 毕业于卡内基·梅隆大学, 开源了许多牛逼的项目, 这个便是其中之一, AFNetworking 采用 NSURLConnection + NSOperation, 主要方便与服务端 API 进行数据交换, 操作简单, 功能强大, 现在

重磅出击 实现IOS下内嵌HTML编辑器 Objective-C 与 JavaScript 通信攻关

通过接近N天的努力. 终于在今天.IOS下内嵌HTML编辑器的Demo 基本实现. 学习过程中,参考了很多网上的资料.很感谢这些分享资源的牛人.有你们.. 才能顺利拿下这个比较特别的需求. 我使用的HTML编辑器是金山开源的 KindEditor         利用UIWebView 加载 KindEditor (也就是我说的内嵌). 实现IOS下用户可以进行富文本编辑. 主要目的是保证服务端的内容值不丢失.亦可在移动端对内容进行一些简单的修改. 途中难点在于,如何与 KindEditor 的

Github上优秀的Objective-C项目简介

Github上优秀的Objective-C项目简介 主要对当前Github排名靠前的项目做一个简单的简介,方便自己快速了解 Objective-C的一些优秀的开源框架. 项目名称 项目信息  AFNetworking 作者是 NSHipster 的博主, iOS 开发界的大神级人物, 毕业于卡内基·梅隆大学, 开源了许多牛逼的项目, 这个便是其中之一, AFNetworking 采用 NSURLConnection + NSOperation, 主要方便与服务端 API 进行数据交换, 操作简单

10款iOS高效开发必备的Objective-C类库

因为iOS SDK相对比较底层,所以开发者就得受累多做一些体力活.不过幸运的是,有很多第三方的类库可以用来简化很多不必要的工作.经过作者团队的慎重讨论,他们 评选出了10款能够极大提高iOS开发效率的类库,根据原文作者的评价来看,基本上有了这10款工具,做iOS开发就真的跟泡Cocoa一样了. MBProgressHUD--进展指示符库 苹果的应用程序一般都会用一种优雅的,半透明的进度显示效果,不过这个API是不公开的,因此你要是用了,很可能被清除出AppStore.而 MBProgressHU

解决一个Django Rest Framework的JSON输出的小问题

  在服务器升级迁移过程中,遇到一个见了鬼的问题. 同样的一个API输出,在本机测试时和生产中一台机器上的输出为纯数据的json格式. 而在另一台生产机器上却为加了统计和跳转信息的另一种json格式. 由于前端用了vue.js作了数据的加载,如果同样的代码,那获取json中对象的信息显然就会发生问题. 解决BUG的时间来不及,也无法深入调试.可用以下代码,判断json中是否有存在对象来进行对象的赋值,可解决这个输出问题. 以后找时间还是深入研究一下这个DRF的输出机制吧. //此处兼容djang

Zend Framework处理Json数据方法详解

本文实例讲述了Zend Framework处理Json数据的方法.分享给大家供大家参考,具体如下: JSON分隔符及意义 {}    用于实现对象的包含,对象都包含在大括号中 ,    逗号用于分隔对象的不同属性,或者数组的元素 []    用于存放数组,数组将存放在中括号中 :    用于表示键/值对的值,冒号前为键,冒号后为该键的值 JSON示例 { "addressbook":{ "name":"Mary Lebow", "add