//my.h
#ifndef __1_Header_h
#define __1_Header_h
#define DEBUG 1
#define aa 1

#ifdef aa
#ifdef DEBUG
#define NSLog(FORMAT, ...) fprintf(stderr,"%s\n",[[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#else
#define NSLog(...)
#endif
#endif

#ifdef bb
#ifdef DEBUG
#define NSLog(FORMAT, ...) fprintf(stderr,"%s:%d\t%s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#else
#define NSLog(...)
#endif
#endif

#endif
//main.m

/*
 {"desc":"OK","status":1000,"data":{"wendu":"25","ganmao":"虽然温度适宜但风力较大,仍较易发生感冒,体质较弱的朋友请注意适当防护。","forecast":[{"fengxiang":"南风","fengli":"4-5级","high":"高温 27℃","type":"晴","low":"低温 20℃","date":"8日星期二"},{"fengxiang":"东南风","fengli":"4-5级","high":"高温 26℃","type":"多云","low":"低温 19℃","date":"9日星期三"},{"fengxiang":"北风","fengli":"4-5级","high":"高温 26℃","type":"晴","low":"低温 18℃","date":"10日星期四"},{"fengxiang":"东北风","fengli":"4-5级","high":"高温 24℃","type":"阴","low":"低温 17℃","date":"11日星期五"},{"fengxiang":"北风","fengli":"4-5级","high":"高温 26℃","type":"多云","low":"低温 19℃","date":"12日星期六"}],"yesterday":{"fl":"4-5级","fx":"西北风","high":"高温 27℃","type":"晴","low":"低温 20℃","date":"7日星期一"},"aqi":"83","city":"大连"}}
     通过城市id获得天气数据,json数据
    http://wthrcdn.etouch.cn/weather_mini?citykey=101070201
 
*/
/*
 //1.创建url地址
 //2.将url数据转换成二进制数据
 //3.将二进制数据转换成对应的字典或者数组
 //4.各种类型转化
 */

#import <Foundation/Foundation.h>
#import "Weather.h"
#import "Data.h"
#import "Foreast.h"
#import "Yesterday.h"
#import "Manager.h"
#import "my.h"

#define PATH @"http://wthrcdn.etouch.cn/weather_mini?citykey=101070201"

int main(int argc, const char * argv[]) {
    @autoreleasepool {

NSURL *url = [[NSURL alloc] initWithString:PATH];
        NSData *data1 = [[NSData alloc] initWithContentsOfURL:url];
        NSDictionary *dictory = [NSJSONSerialization JSONObjectWithData:data1 options:1 error:nil];
        
        Weather *weather = [Weather new];
        Data *data = [Data new];
        Foreast *foreast = [Foreast new];
        Yesterday *yesterday = [Yesterday new];
        weather.date = data;
        data.forecast = foreast;
        data.yesterday = yesterday;
        
        weather.desc = dictory[@"desc"];
        weather.status = dictory[@"status"];
        
        data.wendu = dictory[@"data"][@"wendu"];
        data.ganmao = dictory[@"data"][@"ganmao"];
        data.aqi = dictory[@"data"][@"aqi"];
        data.city = dictory[@"data"][@"city"];
        
        NSArray *array=dictory[@"data"][@"forecast"];
        for (NSDictionary *subDict in array)
        {
            Manager *manager = [Manager new];
            manager.fengxiang = subDict[@"fengxiang"];
            manager.fengli = subDict[@"fengli"];
            manager.high = subDict[@"high"];
            manager.type = subDict[@"type"];
            manager.low = subDict[@"low"];
            manager.date = subDict[@"date"];
            [foreast.marray addObject:manager];
        }
        for (Manager *user in foreast.marray) {
            NSLog(@"fengxiang:%@,fengli:%@,high:%@,type:%@,low:%@,date:%@\n",user.fengxiang,user.fengli,user.high,user.type,user.low,user.date);
        }

NSDictionary *diction1 = dictory[@"data"][@"yesterday"];
        Manager *manager = [Manager new];
        manager.fl1 = diction1[@"fl"];
        manager.fx1 = diction1[@"fx"];
        manager.high1 = diction1[@"high"];
        manager.type1 = diction1[@"type"];
        manager.low1 = diction1[@"low"];
        manager.date1 = diction1[@"date"];
        [yesterday.marray addObject:manager];
        for (Manager *user in yesterday.marray) {
            NSLog(@"fl:%@,fx:%@,high:%@,type:%@,low:%@,date:%@\n",user.fl1,user.fx1,user.high1,user.type1,user.low1,user.date1);
        }
        //NSLog(@"%@",yesterday);
        
        NSLog(@"%@",weather);
    }
    return 0;
}
//Manager.h

//
//  Manager.h
//  homework
//
//  Created by hehe on 15/9/8.
//  Copyright (c) 2015年 wang.hehe. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface Manager : NSObject
@property (nonatomic,strong) NSString * fengxiang;
@property (nonatomic,strong) NSString * fengli;
@property (nonatomic,strong) NSString * high;
@property (nonatomic,strong) NSString * type;
@property (nonatomic,strong) NSString * low;
@property (nonatomic,strong) NSString * date;

@property (nonatomic,strong) NSString * fl1;
@property (nonatomic,strong) NSString * fx1;
@property (nonatomic,strong) NSString * high1;
@property (nonatomic,strong) NSString * type1;
@property (nonatomic,strong) NSString * low1;
@property (nonatomic,strong) NSString * date1;
@end
//Manager.m

//
//  Manager.m
//  homework
//
//  Created by hehe on 15/9/8.
//  Copyright (c) 2015年 wang.hehe. All rights reserved.
//

#import "Manager.h"

@implementation Manager
-(NSString *)description
{
    return [NSString stringWithFormat:@"fengxiang=%@,fengli=%@,high=%@,type=%@,low=%@,date=%@",self.fengxiang,self.fengli,self.high,self.type,self.low,self.date];
}
@end
//Weather.h

//
//  Weather.h
//  homework
//
//  Created by hehe on 15/9/8.
//  Copyright (c) 2015年 wang.hehe. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Data.h"

@interface Weather : NSObject
@property (nonatomic,strong) NSString * desc;
@property (nonatomic,strong) NSString * status;
@property (nonatomic,strong) Data * date;
@end
//Weather.m

//
//  Weather.m
//  homework
//
//  Created by hehe on 15/9/8.
//  Copyright (c) 2015年 wang.hehe. All rights reserved.
//

#import "Weather.h"

@implementation Weather
- (NSString *)description
{
    return [NSString stringWithFormat:@"desc=%@,status=%@,\ndata:%@",self.desc,self.status,self.date];
}
@end
//Yesterday.h

//
//  Yesterday.h
//  homework
//
//  Created by hehe on 15/9/8.
//  Copyright (c) 2015年 wang.hehe. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface Yesterday : NSObject
@property (nonatomic,strong) NSMutableArray * marray;
- (instancetype)init;
@end
//Yesterday.m

//
//  Yesterday.m
//  homework
//
//  Created by hehe on 15/9/8.
//  Copyright (c) 2015年 wang.hehe. All rights reserved.
//

#import "Yesterday.h"

@implementation Yesterday
- (instancetype)init
{
    if (self = [super init])
    {
        _marray = [[NSMutableArray alloc]init];
    }
    return self;
}

//-(NSString *)description
//{
//    return _marray;
//}
@end
//Foreast.h

//
//  Foreast.h
//  homework
//
//  Created by hehe on 15/9/8.
//  Copyright (c) 2015年 wang.hehe. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface Foreast : NSObject
@property (nonatomic,strong) NSMutableArray * marray;
- (instancetype)init;
@end
//Foreast.m

//
//  Foreast.m
//  homework
//
//  Created by hehe on 15/9/8.
//  Copyright (c) 2015年 wang.hehe. All rights reserved.
//

#import "Foreast.h"

@implementation Foreast
- (instancetype)init
{
    if (self = [super init])
    {
        _marray = [[NSMutableArray alloc]init];
    }
    return self;
}

@end
//文件格式

{
    "desc": "OK",
    "status": 1000,
    "data":
    {
        "wendu": "25",
        "ganmao": "虽然温度适宜但风力较大,仍较易发生感冒,体质较弱的朋友请注意适当防护。",
        "forecast": [
                     {
                         "fengxiang": "南风",
                         "fengli": "4-5级",
                         "high": "高温 27℃",
                         "type": "晴",
                         "low": "低温 20℃",
                         "date": "8日星期二"
                     },
                     {
                         "fengxiang": "东南风",
                         "fengli": "4-5级",
                         "high": "高温 26℃",
                         "type": "多云",
                         "low": "低温 19℃",
                         "date": "9日星期三"
                     },
                     {
                         "fengxiang": "北风",
                         "fengli": "4-5级",
                         "high": "高温 26℃",
                         "type": "晴",
                         "low": "低温 18℃",
                         "date": "10日星期四"
                     },
                     {
                         "fengxiang": "东北风",
                         "fengli": "4-5级",
                         "high": "高温 24℃",
                         "type": "阴",
                         "low": "低温 17℃",
                         "date": "11日星期五"
                     },
                     {
                         "fengxiang": "北风",
                         "fengli": "4-5级",
                         "high": "高温 26℃",
                         "type": "多云",
                         "low": "低温 19℃",
                         "date": "12日星期六"
                     }
                     ],
        "yesterday":
        {
            "fl": "4-5级",
            "fx": "西北风",
            "high": "高温 27℃",
            "type": "晴",
            "low": "低温 20℃",
            "date": "7日星期一"
        },
        "aqi": "83",
        "city": "大连"
    }
}

JSON解析保存在类中的更多相关文章

  1. java 写一个JSON解析的工具类

    上面是一个标准的json的响应内容截图,第一个红圈”per_page”是一个json对象,我们可以根据”per_page”来找到对应值是3,而第二个红圈“data”是一个JSON数组,而不是对象,不能 ...

  2. java前端传入的json字符串保存到表中的方法

    表 service_goods_base 字段如下: 传入的json 字符串: servicePictureArray  :  [{"picServiceUrl": "h ...

  3. JSON.net 在实体类中自定义日期的格式

    定义日期格式转换类,其继承 IsoDateTimeConverter,代码如下: public class DateTimeConverter : IsoDateTimeConverter { pub ...

  4. C#字符串数组排序 C#排序算法大全 C#字符串比较方法 一个.NET通用JSON解析/构建类的实现(c#) C#处理Json文件 asp.net使用Jquery+iframe传值问题

    C#字符串数组排序   //排序只带字符的数组,不带数字的 private   string[]   aa   ={ "a ", "c ", "b & ...

  5. flink---实时项目--day02-----1. 解析参数工具类 2. Flink工具类封装 3. 日志采集架构图 4. 测流输出 5. 将kafka中数据写入HDFS 6 KafkaProducer的使用 7 练习

    1. 解析参数工具类(ParameterTool) 该类提供了从不同数据源读取和解析程序参数的简单实用方法,其解析args时,只能支持单只参数. 用来解析main方法传入参数的工具类 public c ...

  6. 《项目经验》--通过js获取前台数据向一般处理程序传递Json数据,并解析Json数据,将前台传来的Json数据写入数据库表中

      先看一下我要实现的功能界面:   这个界面的功能在图中已有展现,课程分配(教师教授哪门课程)在之前的页面中已做好.这个页面主要实现的是授课,即给老师教授的课程分配学生.此页面实现功能的步骤已在页面 ...

  7. 一个.NET通用JSON解析/构建类的实现(c#)转

    转自:http://www.cnblogs.com/xfrog/archive/2010/04/07/1706754.html NET通用JSON解析/构建类的实现(c#) 在.NET Framewo ...

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

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

  9. 通过js获取前台数据向一般处理程序传递Json数据,并解析Json数据,将前台传来的Json数据写入数据库表中

    摘自:http://blog.csdn.net/mazhaojuan/article/details/8592015 通过js获取前台数据向一般处理程序传递Json数据,并解析Json数据,将前台传来 ...

随机推荐

  1. eclipse/MyEclipse 日期格式、注释日期格式、时区问题[转]

    http://www.cnblogs.com/hoojo/archive/2011/03/21/1990070.html 在eclipse/MyEclipse中,如果你的注释或是运行System.ou ...

  2. 【转】Watir, Selenium & WebDriver

    转自:http://watirmelon.com/2010/04/10/watir-selenium-webdriver/ Please also see my new ‘Watir-WebDrive ...

  3. ios开发——仿新版iBooks书本打开与关闭动画

    IOS新版iBooks吸引人的地方除了有干净整洁的界面.方便灵活的操作以及大容量的书籍容量以外.还有其优秀的用户交互,尤其是其动画的使用.打开一本书时书本缓慢放大并打开.关闭一本书后书本关闭并回到原位 ...

  4. TFS 图标意思

    小人:文件被其他人签出 对号:文件被自己签出 锁: 文件已经被签入 加号:新增加一个文件

  5. Codeforces Round #192 (Div. 1) C. Graph Reconstruction 随机化

    C. Graph Reconstruction Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/3 ...

  6. ZOJ 3633 Alice's present 倍增 区间查询最大值

    Alice's present Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/vi ...

  7. WPF基础到企业应用系列7——深入剖析依赖属性(WPF/Silverlight核心)

    一. 摘要 首先圣殿骑士非常高兴这个系列能得到大家的关注和支持.这个系列从七月份開始到如今才第七篇,上一篇公布是在8月2日,掐指一算有二十多天没有继续更新了,最主要原因一来是想把它写好,二来是由于近期 ...

  8. C语言连接MySQL数据库(课程设计总结)

    刚结束课程设计,也预示着假期立即就要到来了.本次课程设计并不算难,无非就是让做一个XXX系统,实现用户的注冊.登录.菜单管理.超级用户等等一些功能,到如今为止已经做过好几个了,所以基本流程都熟悉了! ...

  9. Linux Bash命令关于程序调试详解

    转载:http://os.51cto.com/art/201006/207230.htm 参考:<Linux shell 脚本攻略>Page22-23 Linux bash程序在程序员的使 ...

  10. 几个常用myeclipse快捷键

    Ctrl + D:直接删除光标所在行 Alt + ↑:向上移动光标所在行 Alt + ↓:向下移动光标所在行 Ctrl + Alt + ↑:直接向上复制光标所在行内容 Ctrl + Alt + ↓:直 ...