//
// main.m
// OC8-Json文件解析
//
// Created by qianfeng on 15/6/23.
// Copyright (c) 2015年 qianfeng. All rights reserved.
// #import <Foundation/Foundation.h>
//Json
//Javascript 语法的子集
//key : value 类似OC中的键值对
//1.json文件 的最外层结构通常为字典或者数组,以字典居多.
//2.json数据可以为 基本类型数据,字符串对象,数组对象([]包含),字典对象({}包含),null类型,bool类型
int main(int argc, const char * argv[]) {
@autoreleasepool { #if 0
//1.先把文件的数据读成NSdata对象.
// NSData *data =[NSData dataWithContentsOfFile:<#(NSString *)#>];
NSString *fileString =[NSString stringWithContentsOfFile:@"/Users/qianfeng/Downloads/jsonUserList.txt" encoding:NSUTF8StringEncoding error:nil];
NSData *data =[fileString dataUsingEncoding:NSUTF8StringEncoding];
//2.解析json数据,解析成字典对象还是数组对象,看文件结构
NSDictionary *ditc =[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; NSLog(@" %@",ditc); NSArray *users =[ditc objectForKey:@"users"];
for (NSDictionary *dict in users) {
NSLog(@"name= %@",[dict objectForKey:@"username"]);
} #endif //Json 网址解析 NSURL *url =[NSURL URLWithString:@"http://www.oschina.net/code/snippet_160697_34201"];
NSString *urlString =[NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
//NSLog(@"%@",urlString);
NSData *data =[urlString dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *weatherInfo =[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
NSLog(@" %@",weatherInfo); }
return ;
}

Json文件/网址解析的更多相关文章

  1. iOS开发网络篇-JSON文件的解析

    一.什么是JSON数据 1.JSON的简单介绍 JSON:是一种轻量级的传输数据的格式,用于数据的交互 JSON是javascript语言的一个子集.javascript是个脚本语言(不需要编译),用 ...

  2. JsonCpp——json文件的解析

    定义: 官网: http://json.org/ 在线解析器:http://json.cn/ http://www.bejson.com/ JSON(JavaScript Object Notatio ...

  3. 在Unity中json文件的解析方式

    using System.Collections; using System.Collections.Generic; using UnityEngine; using LitJson; using ...

  4. java读取json文件进行解析,String转json对象

    String jsonFilePath = "C:/a.json"; File file = new File(jsonFilePath ); String input = Fil ...

  5. python读取json文件并解析

    # -*- coding: utf-8 -*- import os import json import sys reload(sys) sys.setdefaultencoding('utf-8') ...

  6. IIS7.5支持解析读取.json文件数据

    在站点中添加 MIME类型去支持Json文件的解析 添加mime类型 文件扩展名:.json MIME类型:application/json 添加成功后即可. 如果不能直接操作iis也可以直接在web ...

  7. java实现服务端守护进程来监听客户端通过上传json文件写数据到hbase中

    1.项目介绍: 由于大数据部门涉及到其他部门将数据传到数据中心,大部分公司采用的方式是用json文件的方式传输,因此就需要编写服务端和客户端的小程序了.而我主要实现服务端的代码,也有相应的客户端的测试 ...

  8. 如何在Hadoop的MapReduce程序中处理JSON文件

    简介: 最近在写MapReduce程序处理日志时,需要解析JSON配置文件,简化Java程序和处理逻辑.但是Hadoop本身似乎没有内置对JSON文件的解析功能,我们不得不求助于第三方JSON工具包. ...

  9. iOS 如何用JSONKit读写JSON文件

     如何用JSONKit读写JSON文件 分类: ios2013-04-20 12:46 510人阅读 评论(0) 收藏 举报 JSON文件格式简单,使用方便,值得一用. 目前已经有多个库支持Json文 ...

随机推荐

  1. javax.naming.NameNotFoundException

    2015-08-27 09:53:16,463 [localhost-startStop-1] DEBUG [org.springframework.jndi.JndiTemplate] - Look ...

  2. 从hello-world 开始 <contiki学习之四>

    按照contiki 官方给出的example下的例子之hello world来说,所有的工程里面都有一个唯一的Makefile.然后这个Makefile会去调用其他makefile文件.于是,一切就从 ...

  3. Sublime Text 备忘

    Sublime Text已经被传成编程利器,那当然也是我们前端的利器了,刚开始用的时候,很多小问题,所以做个备忘,忘记的时候也可以翻出来看看,下次重装的时候可以用到. 1.设置自动换行 菜单栏 Vie ...

  4. ZJU-PAT 1065. A+B and C (64bit) (20)

    Given three integers A, B and C in [-263, 263], you are supposed to tell whether A+B > C. Input S ...

  5. U盘安装Win7 64位系统(笔记本+台式机亲测)

    准备工具: 1. Win7 64位系统的镜像文件(网上随便一搜即可,最好是纯净版,没有一堆乱七八糟的内置软件) 2. 4G以上的U盘一个 所用软件: 老毛桃(官网下载) 具体步骤: 1.数据备份(将原 ...

  6. uva216 c++回溯法

    因为题目要求最多8台电脑,所以可以枚举全排列,然后依次计算距离进行比较,枚举量8!=40320并不大,但这种方法不如回溯法好,当数据再大一些枚举就显得笨拙了,所以这个题我用回溯法做的,回溯有一个好处是 ...

  7. [GIF] The Phase Property in GIF Loop Coder

    In this lesson, we look at one of the most powerful features in GIF Loop Coder, the phase property, ...

  8. git 提交远程

    一.从远程克隆项目,修改后提交 1.先切换要放项目的本地目录 C:\Users\chendd>cd E:\web C:\Users\chendd>e: 2.根据服务器的git地址克隆到本地 ...

  9. MII接口全家福

    转载:http://blog.chinaunix.net/uid-24148050-id-131084.html 简介:    MII是英文Medium Independent Interface的缩 ...

  10. const int * pi/int * const pi的区别

    前面有一篇文章:数组名就是常量指针 参考文章:http://blog.pfan.cn/whyhappy/5164.html const int * pi .int const * pi与int *   ...