88年什么命| 为什么积食发烧很难退| 姨妈量少是什么原因| 头晕晕的是什么原因| 七月有什么花| 葡萄柚是什么| 做梦剪头发是什么意思| 梅毒吃什么药最好| 细胞是什么| 93年鸡五行属什么| 房颤什么症状| 手足口病吃什么药| 赵云字什么| 知青为什么要下乡| 纸尿裤nb是什么码| 降火吃什么| 宋朝后面是什么朝代| 长春有什么特产| 白羊跟什么星座最配| 拉肚子吃什么食物| 洗葡萄用什么洗最干净| 猫什么时候绝育| 面藕是什么做的| 细菌性阴道炎是什么原因引起的| 任达华属什么生肖| 怀孕期间吃什么对胎儿发育好| 探病是什么意思| 势力是什么意思| 口臭是什么原因导致的呢| 冬占生男是什么意思| 灰太狼是什么意思| 脖子上长痘痘什么原因| 世交是什么意思| 过路车是什么意思| 鱼头炖什么好吃| 10月29日是什么星座| 属鸡女和什么属相最配| 诚不我欺什么意思| 保姆是什么意思| 盗汗是什么原因造成的| 为什么会低血压| 香蕉什么时候成熟| 香皂和肥皂有什么区别| 什么菜好消化| 人格魅力是什么意思| 狗皮肤溃烂用什么药| 双肺结节是什么病| 中性粒细胞高是什么感染| 肌肉拉伤用什么药| 银杯子喝水有什么好处| 来例假喝什么好| 安阳车牌号是豫什么| 自贸区是什么意思| 老干部是什么意思| 身体怕热是什么原因| 貂蝉原名叫什么| 风花雪月什么意思| 霏字五行属什么| 扬州有什么特产| 脚气看什么科| 孕期能吃什么| 疝是什么意思| 脚上长水泡是什么原因| 孕期什么时候补铁| 前胸后背出汗是什么原因造成的| 胆汁反流是什么原因引起的| 大肠杆菌用什么药治疗效果好| 确立是什么意思| 腿长身子短有什么说法| 吃什么补气血效果最好| 鸡男配什么属相最好| 兔死狐悲指什么生肖| 宫内膜回声不均匀是什么意思| 三头六臂指什么生肖| 什么颜色最吸热| 封神是什么意思| 鸡炖什么补气血| 桂花是什么颜色的| 阴历7月22是什么日子| 吃什么增强性功能| 老年人心慌是什么原因| 红花跟藏红花有什么区别| 什么是冬虫夏草| 八月三十日是什么星座| 痰多吃什么药| 史密斯夫妇什么意思| 宫外孕什么意思| 已读不回是什么意思| 10月23号是什么星座| 中医减肥挂什么科| 代偿是什么意思| 圣杯是什么意思| 骇人听闻是什么意思| 白条鱼是什么鱼| 肚子胀不排便什么原因| 肾亏是什么意思| 水代表什么生肖| 卵泡是什么意思| 抑郁挂什么科| 2月是什么星座的| 泰国有什么好玩| 麝香是什么味道| 维生素b6主治什么病| 太形象了是什么意思| 钰字五行属什么| 什么去甲醛最快有效| s档是什么档| 经期上火了吃什么降火| 房间为什么有蟑螂| 三国是什么朝代| orange是什么颜色| 一级军士长什么级别| 蝙蝠是什么类| 托帕石是什么宝石| 肺疼是什么原因| 六月是什么季节| 长期咳嗽是什么原因| 颈椎病看什么科最好| 尿毒症有什么症状| 宣发是什么意思| 婴儿打嗝是什么原因引起的| 下肢血栓吃什么药| 甲基蓝治疗什么鱼病| 疱疹是什么症状| 经常放屁是什么原因造成的| mac代表什么| 沸石为什么能防止暴沸| 自身免疫性胃炎是什么意思| 手忙脚乱是什么意思| 看望病人买什么水果| 肚子胀气吃什么药好得快| 低血压什么症状| 受凉了吃什么药| 心绞痛吃什么药最好| 鼻烟为什么没人吸了| 麦粒肿涂什么药膏| 心发慌是什么原因| 信阳毛尖属于什么茶| 落叶像什么| 牙龈和牙齿分离是什么原因| 单纯性肥胖是什么意思| 词又被称为什么| nbr是什么材质| 什么话是世界通用的| 什么是压缩性骨折| 山楂泡水喝有什么功效| 洒水车的音乐是什么歌| 男人吃什么补肾| 黄瓜籽粉有什么作用| 实至名归是什么意思| 肠胃感冒吃什么食物| 睡醒后腰疼是什么原因| rock是什么意思| 空腹血糖受损是什么意思| 什么是阴历什么是阳历| usim卡是什么卡| 洗耳恭听是什么意思| 怀孕一个月有什么症状| 腋臭挂什么科| Continental什么牌子| 白矾和明矾有什么区别| 美平是什么药| 1946年属什么生肖| 着凉拉肚子吃什么药| 甲床是什么| 属鸡适合佩戴什么饰品| 七月一日什么节| 什么是糖尿病| 瓜尔胶是什么东西| 左腰疼痛是什么原因男性| 死有余辜是什么意思| 夏天喝什么茶减肥| 凝是什么意思| 什么是无氧运动| 晚上吃什么水果减肥效果最好| 尿细菌计数高是什么原因| 益禾堂什么好喝| 中考送什么礼物| 鱼吃什么| 五黄煞是什么意思| 淋巴细胞降低说明什么| 桂枝是什么| 血糖偏高能吃什么水果和食物最好| 247什么意思| tbs和tct有什么区别| 脚背抽筋是什么原因引起的| 什么时候满月| 枸杞与菊花一起泡水喝有什么功效| 皮卡丘什么意思| 陈皮有什么功效作用| 女票什么意思| sp是什么面料成分| 622是什么星座| 疱疹是什么| 依靠是什么意思| 梦见洗鞋子是什么意思| 龟头起红点用什么药| 三七有什么功效和作用| 喝盐水有什么作用和功效| 梦到自己掉头发是什么预兆| 什么是处女| fmp是什么意思| 什么茶降火| 悦字属于五行属什么| 经血发黑什么原因| 槟榔为什么会上瘾| 芋头不能和什么一起吃| 一什么清风| 喜面是什么意思| 报道是什么意思| 山地自行车什么牌子好| 曼陀罗是什么| 冬瓜和什么不能一起吃| 尿分叉吃什么药能治好| 什么季节减肥效果最快最好| 心急如焚是什么意思| 痰核是什么意思| 本能是什么意思| 芳心暗许什么意思| 孙膑原名叫什么| 为什么不能踩死蜈蚣| 剪不断理还乱什么意思| 肝血管瘤有什么症状| 附件囊肿吃什么药最好| 犹太人说什么语言| 石女什么意思| 神经大条是什么意思| 颈椎痛挂什么科| 劲酒是什么酒| 什么是水痘| 梦见手机失而复得是什么意思| 什么游戏赚钱| 尿道感染挂什么科| 弯弯的月儿像什么| 肿瘤是什么样子的| 彩超和ct有什么区别| 额是什么意思| ram是什么动物| 将军是什么级别| 面肌痉挛是什么原因引起的| 吃什么不会胖又减肥| 慎重考虑是什么意思| 流鼻血是什么原因| 气血不足有什么症状| 画五行属什么| 外阴白斑用什么药最好| 腺肌症吃什么食物好| 职业年金什么时候领取| 甲状腺球蛋白抗体高说明什么| 翩跹是什么意思| 什么是性行为| 琅玕是什么意思| 口加至念什么| 肚子疼拉肚子挂什么科| 牛肉饺子馅配什么蔬菜好吃| 挂妇科门诊都检查什么| 腺肌瘤是什么病| 尿频尿急尿不尽吃什么药最快见效| 泡椒是什么辣椒| 渐入佳境是什么意思| pop是什么意思| 孝顺的真正含义是什么| 姻缘是什么意思| 包皮红肿瘙痒用什么药| 百度
Skip to content

SBJson/SBJson

SBJson 5

Chunk-based JSON parsing and generation in Objective-C.

CircleCI Project Status: Inactive - The project has reached a stable, usable state but is no longer being actively developed; support/maintenance will be provided as time allows. Carthage compatible

Overview

SBJson's number one feature is stream/chunk-based operation. Feed the parser one or more chunks of UTF8-encoded data and it will call a block you provide with each root-level document or array. Or, optionally, for each top-level entry in each root-level array.

With this you can reduce the apparent latency for each download/parse cycle of documents over a slow connection. You can start parsing and return chunks of the parsed document before the full document has downloaded. You can also parse massive documents bit by bit so you don't have to keep them all in memory.

SBJson maps JSON types to Objective-C types in the following way:

JSON Type Objective-C Type
null NSNull
string NSString
array NSMutableArray
object NSMutableDictionary
true -[NSNumber numberWithBool: YES]
false -[NSNumber numberWithBool: NO]
number NSNumber
  • Booleans roundtrip properly even though Objective-C doesn't have a dedicated class for boolean values.
  • Integers use either long long or unsigned long long if they fit, to avoid rounding errors. For all other numbers we use the double type, with all the potential rounding errors that entails.

"Plain" Chunk Based Parsing

First define a simple block & an error handler. (These are just minimal examples. You should strive to do something better that makes sense in your application!)

SBJson5ValueBlock block = ^(id v, BOOL *stop) {
    BOOL isArray = [v isKindOfClass:[NSArray class]];
    NSLog(@"Found: %@", isArray ? @"Array" : @"Object");
};

SBJson5ErrorBlock eh = ^(NSError* err) {
    NSLog(@"OOPS: %@", err);
    exit(1);
};

Then create a parser and add data to it:

id parser = [SBJson5Parser parserWithBlock:block
                              errorHandler:eh];

id data = [@"[true," dataWithEncoding:NSUTF8StringEncoding];
[parser parse:data]; // returns SBJson5ParserWaitingForData

// block is not called yet...

// ok, now we add another value and close the array

data = [@"false]" dataWithEncoding:NSUTF8StringEncoding];
[parser parse:data]; // returns SBJson5ParserComplete

// the above -parse: method calls your block before returning.

Alright! Now let's look at something slightly more interesting.

Handling multiple documents

This is useful for something like Twitter's feed, which gives you one JSON document per line. Here is an example of parsing many consequtive JSON documents, where your block will be called once for each document:

id parser = [SBJson5Parser multiRootParserWithBlock:block
                                       errorHandler:eh];

// Note that this input contains multiple top-level JSON documents
id data = [@"[]{}" dataWithEncoding:NSUTF8StringEncoding];
[parser parse:data];
[parser parse:data];

The above example will print:

Found: Array
Found: Object
Found: Array
Found: Object

Unwrapping a gigantic top-level array

Often you won't have control over the input you're parsing, so can't use a multiRootParser. But, all is not lost: if you are parsing a long array you can get the same effect by using an unwrapRootArrayParser:

id parser = [SBJson5Parser unwrapRootArrayParserWithBlock:block
                                             errorHandler:eh];

// Note that this input contains A SINGLE top-level document
id data = [@"[[],{},[],{}]" dataWithEncoding:NSUTF8StringEncoding];
[parser parse:data];

Other features

  • For safety there is a max nesting level for all input. This defaults to 32, but is configurable.
  • The writer can sort dictionary keys so output is consistent across writes.
  • The writer can create human-readable output, with newlines and indents.
  • You can install SBJson v3, v4 and v5 side-by-side in the same application. (This is possible because all classes & public symbols contains the major version number.)

A word of warning

Stream based parsing does mean that you lose some of the correctness verification you would have with a parser that considered the entire input before returning an answer. It is technically possible to have some parts of a document returned as if they were correct but then encounter an error in a later part of the document. You should keep this in mind when considering whether it would suit your application.

American Fuzzy Lop

I've run AFL on the sbjson binary for over 24 hours, with no crashes found. (I cannot reproduce the hangs reported when attempting to parse them manually.)

                       american fuzzy lop 2.35b (sbjson)

┌─ process timing ─────────────────────────────────────┬─ overall results ─────┐
│        run time : 1 days, 0 hrs, 45 min, 26 sec      │  cycles done : 2      │
│   last new path : 0 days, 0 hrs, 5 min, 24 sec       │  total paths : 555    │
│ last uniq crash : none seen yet                      │ uniq crashes : 0      │
│  last uniq hang : 0 days, 2 hrs, 11 min, 43 sec      │   uniq hangs : 19     │
├─ cycle progress ────────────────────┬─ map coverage ─┴───────────────────────┤
│  now processing : 250* (45.05%)     │    map density : 0.70% / 1.77%         │
│ paths timed out : 0 (0.00%)         │ count coverage : 3.40 bits/tuple       │
├─ stage progress ────────────────────┼─ findings in depth ────────────────────┤
│  now trying : auto extras (over)    │ favored paths : 99 (17.84%)            │
│ stage execs : 603/35.6k (1.70%)     │  new edges on : 116 (20.90%)           │
│ total execs : 20.4M                 │ total crashes : 0 (0 unique)           │
│  exec speed : 481.9/sec             │   total hangs : 44 (19 unique)         │
├─ fuzzing strategy yields ───────────┴───────────────┬─ path geometry ────────┤
│   bit flips : 320/900k, 58/900k, 5/899k             │    levels : 8          │
│  byte flips : 0/112k, 4/112k, 3/112k                │   pending : 385        │
│ arithmetics : 66/6.24M, 0/412k, 0/35                │  pend fav : 1          │
│  known ints : 5/544k, 0/3.08M, 0/4.93M              │ own finds : 554        │
│  dictionary : 0/0, 0/0, 29/1.83M                    │  imported : n/a        │
│       havoc : 64/300k, 0/0                          │ stability : 100.00%    │
│        trim : 45.19%/56.5k, 0.00%                   ├────────────────────────┘
^C────────────────────────────────────────────────────┘             [cpu: 74%]

+++ Testing aborted by user +++
[+] We're done here. Have a nice day!

API Documentation

Please see the API Documentation for more details.

Installation

CocoaPods

The preferred way to use SBJson is by using CocoaPods. In your Podfile use:

pod 'SBJson', '~> 5.0.0'

Carthage

SBJson is compatible with Carthage. Follow the Getting Started Guide for iOS.

github "SBJson/SBJson" == 5.0.2

Bundle the source files

An alternative that I no longer recommend is to copy all the source files (the contents of the Classes folder) into your own Xcode project.

Examples

Support

  • Review (or create) StackOverflow questions tagged with SBJson if you have questions about how to use the library.
  • Use the issue tracker if you have found a bug.
  • I regret I'm only able to support the current major release.

Philosophy on backwards compatibility

SBJson practice Semantic Versioning, which means we do not break the API in major releases. If something requires a backwards-incompatible change, we release a new major version. (Hence why a library of less than 1k lines has more major versions than Emacs.)

I also try support a gradual migration from one major version to the other by allowing the last three major versions to co-exist in the same app without conflicts. The way to do this is putting the major version number in all the library's symbols and file names. So if v6 ever comes out, the SBJson5Parser class would become SBJson6Parser, etc.

License

BSD. See LICENSE for details.

About

This framework implements a strict JSON parser and generator in Objective-C.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Contributors 31

身份证最后一位x是什么意思 开导是什么意思 不言而喻的喻是什么意思 用盐刷牙有什么好处和坏处 白天梦见蛇是什么预兆
女人鼻头有痣代表什么 骶管囊肿是什么意思 时来运转是什么意思 k代表什么意思 似水年华是什么意思
梦见跳舞是什么意思 移交是什么意思 精分什么意思 肠胃不舒服吃什么 noon什么意思
玉树临风是什么生肖 做尿常规挂什么科 宝宝老是摇头是什么原因 怜香惜玉是什么意思 夜间尿多是什么原因
月经期能吃什么水果hcv9jop0ns8r.cn 蛋白质变性的本质是什么hcv7jop9ns6r.cn 真菌性龟头炎用什么药creativexi.com 如履薄冰什么意思kuyehao.com 往届毕业生是什么意思hcv7jop6ns5r.cn
肚子两侧疼是什么原因hcv7jop7ns4r.cn 什么降血脂效果最好的hcv8jop7ns2r.cn bnp是什么检查hcv9jop4ns9r.cn 牙齿酸是什么原因wzqsfys.com 什么是牛黄hcv8jop2ns2r.cn
琥珀酱是什么味hcv9jop8ns3r.cn 尿酸高都有什么症状hcv9jop3ns3r.cn eod是什么意思ff14chat.com 每天起床口苦口臭是什么原因qingzhougame.com 女性血热吃什么好得快hcv8jop9ns3r.cn
副部长是什么级别kuyehao.com pbc是什么hcv9jop1ns2r.cn 孕妇为什么不能吃桃子hcv9jop5ns8r.cn 总胆红素是什么hcv8jop9ns6r.cn 弱肉强食是什么意思hcv9jop4ns4r.cn
百度