- (IBAction)accessInterfaceBtnPressed:(id)sender {
    
    NSError *error;
    NSString *URL=@"https://api.thinkpage.cn/v3/life/suggestion.json?key=aacuhmmvipa30v3f&location=shanghai&language=zh-Hans";
    //加载一个NSURL对象
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:URL]];
    //将请求的url数据放到NSData对象中
    NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    //IOS5自带解析类NSJSONSerialization从response中解析出数据放到字典中
    NSDictionary *weatherDic = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
   // NSLog(@"All: %@", weatherDic );
    NSDictionary *weatherInfo = [weatherDic objectForKey:@"results"];
    
    NSArray * resultArray=[weatherDic objectForKey:@"results"];
    // NSLog(@"dictionary length is: %d",[weatherInfo count]);
    // NSLog(@"weatherInfo: %@", weatherInfo );
    // NSString *updateTime=[weatherInfo objectForKey:@"last_update"];
    NSLog(@"updateTime: %@", [weatherInfo valueForKey:@"last_update"] );
    //[resultArray valueForKey:@"location"]valueForKey:@"name" ]

NSArray *name=[[resultArray valueForKey:@"location"]valueForKey:@"name"];
    NSString *shanghai=name[0];
    
    //NSString *stringData = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    
   // NSString *resultStr=[[NSString alloc]initWithUTF8String:@"aaa"];
    NSLog(@"shanghai: %@", shanghai);
    
    
    NSDictionary *locationInfo = [weatherInfo valueForKey:@"location"];
    
   
    //NSLog(@"last_update: %@", [weatherInfo objectForKey:@"last_update"] );
    // NSMutableString *name=[locationInfo valueForKey:@"name"];
    // NSLog(@"name: %@", name);
   // NSString*jsonString = [[NSString alloc]initWithBytes:[data bytes] length:[data length] encoding:NSUTF8StringEncoding] ;
    // NSData *data=[locationInfo valueForKey:@"name"];
    [self textView].text = shanghai;
}

参考:

https://temboo.com/ios/parsing-json

  How it appears in the JSON string
NSArray "name": [
NSObject "name": {

另外, 原来()是特么一个数组的意思...搞得我各种找编码的方法...嫩娘...怪我罗....

iOS原生JSON解析.的更多相关文章

  1. 原生JSON解析

    原生JSON解析 JSONObject:JSON数据封装对象JSONArray:JSON数据封装数组 布局: <?xml version="1.0" encoding=&qu ...

  2. iOS中JSON解析三方库的比较

    网络数据解析框架 1.  JsonModel 一个 JSON 模型转换库,有着比较简洁的接口.Model 需要继承自 JSONModel. 2.  yyModel yyModel比较轻量(算上.h 只 ...

  3. IOS中Json解析的四种方法

    作为一种轻量级的数据交换格式,json正在逐步取代xml,成为网络数据的通用格式. 有的json代码格式比较混乱,可以使用此“http://www.bejson.com/”网站来进行JSON格式化校验 ...

  4. 【转】IOS中Json解析的四种方法

    原文网址:http://blog.csdn.net/enuola/article/details/7903632 作为一种轻量级的数据交换格式,json正在逐步取代xml,成为网络数据的通用格式. 有 ...

  5. iOS开源JSON解析库MJExtension

    iOS中JSON与NSObject互转有两种方式:1.iOS自带类NSJSONSerialization 2.第三方开源库SBJSON.JSONKit.MJExtension.项目中一直用MJExte ...

  6. iOS开发-JSON解析

    JSON(JavaScript Object Notation)在网络传输中几乎无处不在,JSON是一种轻量级的数据交换格式,是基于JavaScript(Standard ECMA-262 3rd E ...

  7. iOS 中json解析数据出现中文乱码的问题

    一般服务器的编码格式都是UTF8,这样通过json解析下来的的数据,一般中文是不会出现乱码,但是如果服务器的编码格式不是UTF8,通过json解析的数据中的中文容易出现luan乱码,怎么解决这个问题呢 ...

  8. .Net Core 3.0原生Json解析器

    微软官方博客中描述了为什么构造了全新的Json解析器而不是继续使用行业准则Json.Net 微软博客地址:https://devblogs.microsoft.com/dotnet/try-the-n ...

  9. iOS SDK原生JSON解析

    - (IBAction)touchReadButton:(id)sender { NSData *jsonData = [[NSData alloc] initWithContentsOfFile:J ...

随机推荐

  1. iOS Architecture和Valid architectures

    目前ios的指令集有以下几种: 1,armv6,支持的机器iPhone,iPhone2,iPhone3G及对应的iTouch 2,armv7,支持的机器iPhone4,iPhone4S 3,armv7 ...

  2. iOS 使用XCode6打开项目以后再用XCode5出现的问题fatal error: malformed or corrupted AST file: 'Unable to load module

    使用不同版本的XCode出现的问题: fatal error: malformed or corrupted AST file: 'Unable to load module "/Users ...

  3. iOS 使用Xcode和Instruments调试解决iOS内存泄露(链接转)

    http://blog.csdn.net/totogo2010/article/details/8233565

  4. iOS GCD简单使用

    Grand Central Dispatch (GCD) 1)运行在主线程的Main queue,通过dispatch_get_main_queue获取. /*!* @function dispatc ...

  5. Change Tracking of SQLServer

    1.Enable the change tracking at the database level. ALTER DATABASE AdventureWorks2008 SET CHANGE_TRA ...

  6. 构建LINUX下的入侵检测系统——LIDS 系统管理命令--vlock

    构建LINUX下的入侵检测系统——LIDS   系统管理命令--vlock http://blog.chinaunix.net/uid-306663-id-2440200.html LIDS官方网站: ...

  7. Android java取得当前日期增加一天或多天

    SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd"); Calendar c = Calendar.getInstanc ...

  8. DOS - for

    遍历当前目录,显示文件/文件夹列表 for /f "usebackq" %i in (`dir /b`) do echo %i 注意点: 1.%i用于dos窗口,batch中需要使 ...

  9. RabbitMQ学习总结 第六篇:Topic类型的exchange

    目录 RabbitMQ学习总结 第一篇:理论篇 RabbitMQ学习总结 第二篇:快速入门HelloWorld RabbitMQ学习总结 第三篇:工作队列Work Queue RabbitMQ学习总结 ...

  10. BI系统规划前需要准备的6项工作

    通常在进行商业智能信息系统项目之前,可以先从明确经营分析的愿景和目的入手,确定分析方法和工具.设计经营分析框架.设计指标和报表.IT实现和持续改进机制建立等几个步骤,即先有经营分析体系再有商业智能.第 ...