六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 154|回复: 0

UITableView 分页显示,数据源远程数据,使用JSON格式 [xcode 4.4.1]

[复制链接]

升级  64%

8

主题

8

主题

8

主题

童生

Rank: 1

积分
32
 楼主| 发表于 2012-10-24 22:59:18 | 显示全部楼层 |阅读模式
在这篇里,我们要学习的目标:
         
  • 1. 解析远程的JSON数据     
  • 2. 分页显示数据     
  • 3. 学习Category的使用
概述

    IOS5.0开始支持JSON,所以不用第三方的解析了,主要用于这三个对象:NSDictionary、NSData、NSJSONSerializatio
今天我们做一个天气预报数据的展示,通过国家气象局提供的天气预报接口来获取数据。注:以实现功能为主,不做过多的界面上展示
接口地址:

         
  • http://www.weather.com.cn/data/sk/101010100.html     
  • http://www.weather.com.cn/data/cityinfo/101010100.html     
  • http://m.weather.com.cn/data/101010100.html
    以第三个地址显示内容最全,我们就以这个地获取数据,返回的数据格式如下:   

View Code <div id="cnblogs_code_open_7fbcaa60-ca8c-4cf6-b19c-9d32f996306b" class="cnblogs_code_hide"> 1 {
2     "weatherinfo":{
3         "city":"北京",
4         "city_en":"beijing",
5         "date_y":"2012年9月5日",
6         "date":"",
7         "week":"星期三",
8         "fchh":"11",
9         "cityid":"101010100",
10         "temp1":"27&#8451;~17&#8451;",
11         "temp2":"24&#8451;~17&#8451;",
12         "temp3":"25&#8451;~17&#8451;",
13         "temp4":"27&#8451;~16&#8451;",
14         "temp5":"28&#8451;~17&#8451;",
15         "temp6":"26&#8451;~17&#8451;",
16         "tempF1":"80.6&#8457;~62.6&#8457;",
17         "tempF2":"75.2&#8457;~62.6&#8457;",
18         "tempF3":"77&#8457;~62.6&#8457;",
19         "tempF4":"80.6&#8457;~60.8&#8457;",
20         "tempF5":"82.4&#8457;~62.6&#8457;",
21         "tempF6":"78.8&#8457;~62.6&#8457;",
22         "weather1":"晴转阴",
23         "weather2":"阵雨",
24         "weather3":"阵雨转多云",
25         "weather4":"多云转晴",
26         "weather5":"晴",
27         "weather6":"多云转阵雨",
28         "img1":"0",
29         "img2":"2",
30         "img3":"3",
31         "img4":"99",
32         "img5":"3",
33         "img6":"1",
34         "img7":"1",
35         "img8":"0",
36         "img9":"0",
37         "img10":"99",
38         "img11":"1",
39         "img12":"3",
40         "img_single":"0",
41         "img_title1":"晴",
42         "img_title2":"阴",
43         "img_title3":"阵雨",
44         "img_title4":"阵雨",
45         "img_title5":"阵雨",
46         "img_title6":"多云",
47         "img_title7":"多云",
48         "img_title8":"晴",
49         "img_title9":"晴",
50         "img_title10":"晴",
51         "img_title11":"多云",
52         "img_title12":"阵雨",
53         "img_title_single":"晴",
54         "wind1":"微风",
55         "wind2":"微风",
56         "wind3":"微风",
57         "wind4":"微风",
58         "wind5":"微风",
59         "wind6":"微风",
60         "fx1":"微风",
61         "fx2":"微风",
62         "fl1":"小于3级",
63         "fl2":"小于3级",
64         "fl3":"小于3级",
65         "fl4":"小于3级",
66         "fl5":"小于3级",
67         "fl6":"小于3级",
68         "index":"暖",
69         "index_d":"较凉爽,建议着长袖衬裤等春秋过渡装。体弱者宜着长袖衬衫和马甲。但昼夜温差较大,请适当增减衣服。",
70         "index48":"暖",
71         "index48_d":"较凉爽,建议着长袖衬衫加单裤等春秋过渡装。年老体弱者宜着针织长袖衬衫、马甲和长裤。",
72         "index_uv":"中等",
73         "index48_uv":"弱",
74         "index_xc":"不宜",
75         "index_tr":"适宜",
76         "index_co":"较舒适",
77         "st1":"26",
78         "st2":"17",
79         "st3":"22",
80         "st4":"16",
81         "st5":"23",
82         "st6":"17",
83         "index_cl":"适宜",
84         "index_ls":"适宜",
85         "index_ag":"易发"
86     }
87 }
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表