JSON解析例子
//解析的东西是数组就用数组接受,是字典就用字典接受
//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.c
#import <Foundation/Foundation.h>
#import "Users.h"
#import "my.h"
#define PATH2 @"http://10.0.8.8/sns/my/user_list.php?number=20&page=1"
int main(int argc, const char * argv[]) {
@autoreleasepool {
//创建一个URL
NSURL *url = [NSURL URLWithString:PATH2];
//发送请求来获得返回的JSON数据
NSData *data = [[NSData alloc] initWithContentsOfURL:url];
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:1 error:nil];
NSArray *array = [dic objectForKey:@"users"];
NSMutableArray *marray = [NSMutableArray new];
for(id obj in array)
{
NSLog(@"username:%@,credit:%@",obj[@"username"],obj[@"credit"]);
Users *users = [Users new];
users.name = obj[@"username"];
users.cre = obj[@"credit"];
[marray addObject:users];
}
for(Users *user in marray)
{
NSLog(@"uid:%@,username:%@",user.name,user.cre);
}
}
return 0;
}
//Users.h
//
// Users.h
// Json
//
// Created by hehe on 15/9/8.
// Copyright (c) 2015年 wang.hehe. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface Users : NSObject
@property (nonatomic,strong)NSString * name;
@property (nonatomic,strong)NSString *cre;
@end
//Users.m
//
// Users.m
// Json
//
// Created by hehe on 15/9/8.
// Copyright (c) 2015年 wang.hehe. All rights reserved.
//
#import "Users.h"
@implementation Users
@end
JSON解析例子的更多相关文章
- android json解析及简单例子
JSON的定义: 一种轻量级的数据交换格式,具有良好的可读和便于快速编写的特性.业内主流技术为其提供了完整的解决方案(有点类似于正则表达式 ,获得了当今大部分语言的支持),从而可以在不同平台间进行数据 ...
- 【转】android json解析及简单例子
JSON的定义: 一种轻量级的数据交换格式,具有良好的可读和便于快速编写的特性.业内主流技术为其提供了完整的解决方案(有点类似于正则表达式 ,获得了当今大部分语言的支持),从而可以在不同平台间进行数据 ...
- android json解析及简单例子+Android与服务器端数据交互+Android精彩案例【申明:来源于网络】
android json解析及简单例子+Android与服务器端数据交互+Android精彩案例[申明:来源于网络] android json解析及简单例子:http://www.open-open. ...
- C# Newtonsoft.Json解析数组的小例子[转]
https://blog.csdn.net/Sayesan/article/details/79756738 C# Newtonsoft.Json解析数组的小例子 http://www.cnblog ...
- delphi c++builder JSON 生成与解析 例子
json,System.JSON,REST.JSON JSON有两种数据结构,对象和数组. 对象在js中表示为“{}”括起来的内容,数据结构为 {key:value,key:value,...} 数组 ...
- 解析3级JSON的例子
我们都知道现在Ajax盛行,而且前后台数据交流的格式已经换成了JSON了.虽然我对这种做法还是有点担忧的,如果用户关闭了JavaScript怎么办?但是这些担忧还是不能阻止Ajax的盛行和JSON数据 ...
- Json解析工具Jackson(使用注解)
原文http://blog.csdn.net/nomousewch/article/details/8955796 接上一篇文章Json解析工具Jackson(简单应用),jackson在实际应用中给 ...
- Json解析工具Jackson(简单应用)
原文http://blog.csdn.net/nomousewch/article/details/8955796 概述 Jackson库(http://jackson.codehaus.org),是 ...
- JAVA自已设计JSON解析器
当然,有很多很好的JSON解析的JAR包,比如JSONOBJECT,GSON,甚至也有为我们测试人员而打造的JSONPATH,但我还是自已实现了一下(之前也实现过,现在属于重构). 思想是这样的,以这 ...
随机推荐
- Hash Table构建
get-item e:\test\* |format-table @{name="aa";expression={$_.name.tostring().split(".& ...
- Codeforces Testing Round #12 C. Subsequences 树状数组维护DP
C. Subsequences Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...
- Codeforces Gym 100733A Shitália 计算几何
ShitáliaTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.acti ...
- delphi 带历史信息的菜单
带历史信息的菜单 实例说明 在有些软件中,菜单栏中可以记录已经打开过的文件信息,使用户操作简单.快捷.当用户要打开已打开过的文件时,不需要重复查找,只需选择菜单中打开过的文件,即可实现打开该文件的操作 ...
- ROR 环境的 搭建
1)安装RUBY:从 http://www.ruby-lang.org/en/ 下载 ruby182-15.exe,安装Ruby.ruby -v 看是否安装成功.2)安装RAILS框架 :gem in ...
- [Javascript] IO Functor
IO functor doesn't like Maybe(), Either() functors. Instead of get a value, it takes a function. API ...
- [AngularJS] Isolate State Mutations in Angular Components
Managing state is one of the hardest things to do in any application. Angular 2 tackles this problem ...
- zend studio 函数不提醒 小黄图标 小黄标
在用 Zend Studio 编写 PHP 项目时发现调用系统函数时调试正常, 但是在编写代码时却提示函数未定义"Call to undefined function ", 在左侧 ...
- Uploadify帮助文档
auto 当文件被添加到队列时,自动上传. (字符串) buttonImg 浏览按钮的背景图片路径. (字符串) buttonText 默认在按钮上显示的文本. (字符串) cancelImg 取消按 ...
- c语言海量数据处理
教你如何迅速秒杀掉:99%的海量数据处理面试题 http://wenku.baidu.com/view/4546d06ca45177232f60a276.html c语言如何对海量数据进行处理 PDF ...