- (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. Mysqldump 参数详解(全)

    Mysqldump 参数详解(全) http://www.open-open.com/lib/view/open1358172843762.html mysqldump -S /tmp/mysql33 ...

  2. How to Detect and Track Object With OpenCV

    http://www.intorobotics.com/how-to-detect-and-track-object-with-opencv/

  3. 我就是认真:Linux SWAP 深度解读(必须收藏)

    我就是认真:Linux SWAP 深度解读(必须收藏) http://mp.weixin.qq.com/s?__biz=MzA4Nzg5Nzc5OA==&mid=2651660097& ...

  4. Using Amazon API Gateway with microservices deployed on Amazon ECS

    One convenient way to run microservices is to deploy them as Docker containers. Docker containers ar ...

  5. 微信的公众号unionid

    此外,由于开发者经常有需在多个平台(移动应用.网站.公众帐号)之间共通用户帐号,统一帐号体系的需求,微信开放平台(open.weixin.qq.com)提供了UnionID机制.开发者可通过OpenI ...

  6. 在struts里使用Kindeditor注意事项

    struts配置文件里 <filter-mapping>          <filter-name>struts2</filter-name>          ...

  7. [c++基本语法]——构造函数初始化列表

    c++构造函数初始化成员变量列表: #pragma once class Node { public: int data; // 权值 Node *parent; // 父节点 Node *left; ...

  8. 《30天自制操作系统》09_day_学习笔记

    harib06a: 在昨天的最后一部分,我们已经变成了32位的模式,目的就是希望能够使用电脑的全部内存. 虽然鼠标的显示处理有一些叠加问题,不过笔者为了不让我们感到腻烦,先带我们折腾一下内存 这里笔者 ...

  9. Lintcode: Rehashing

    The size of the hash table is not determinate at the very beginning. If the total size of keys is to ...

  10. C++动态内存分配

    C++动态内存分配1.堆内存分配 :C/C++定义了4个内存区间:代码区,全局变量与静态变量区,局部变量区即栈区,动态存储区,即堆(heap)区或自由存储区(free store). 堆的概念:通常定 ...