首页 / 操作系统 / Linux / iOS中NSJSONSerialization解析JSON数据暨google地理信息处理案例
在iOS开发中,涉及到从网络取得json格式的数据处理工作时,我们会想到很多开源的第三方包,如SBJSON。在iOS5开始,也增加了对json格式数据的处理能力,增加的类是NSJSONSerialization。 使用NSJSONSerialization,可以分析各种复杂格式json数据。 使用的类方法是+ (id)JSONObjectWithData:(NSData *)data options:(NSJSONReadingOptions)opt error:(NSError **)error。 根据不同data的结构,设置不同的option。这里option有三类:NSJSONReadingMutableContainers, NSJSONReadingMutableLeaves , NSJSONReadingAllowFragments。 apple文档对这三种方法做了说明。 1、NSJSONReadingMutableContainers Specifies that arrays and dictionaries are created as mutable objects. 2、NSJSONReadingMutableLeaves Specifies that leaf strings in the JSON object graph are created as instances of NSMutableString. 3、NSJSONReadingAllowFragments Specifies that the parser should allow top-level objects that are not an instance of NSArray or NSDictionary. Available in iOS 5.0 and later.