//
// 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. UVa657 The die is cast

    // 题意:给一个图案,其中'.'表示背景,非'.'字符组成的连通块为筛子.每个筛子里又包含两种字符,其中'X'组成的连通块表示筛子上的点 // 统计每个筛子里有多少个"X"连通块 ...

  2. 得到内网域管理员的5种常见方法<转>

    1.Netbios and LLMNR Name Poisoning 这个方法在WIN工作组下渗透很有用,WIN的请求查询顺序是下面三个步骤:本地hosts文件(%windir%\System32\d ...

  3. ios 7.1 7.1.1 半完美越狱后 电脑訪问手机越狱文件夹的方法

    7.1和7.1.1因为越狱不成熟,半完美越狱后电脑上无法訪问系统越狱文件夹,如var usr 等等. 今天有些意外地发现,能够在电脑上使用手机的越狱文件夹我手机 i4 7.1.1 联通 半完美越狱,没 ...

  4. JQuery UI Widget Factory官方Demo

    <!doctype html> <html lang="en"> <head> <meta charset="utf-8&quo ...

  5. OpenCV 2.2版本号以上显示图片到 MFC 的 Picture Control 控件中

    OpenCV 2.2 以及后面的版本号取消掉了 CvvImage.h 和CvvImage.cpp 两个文件,直接导致了苦逼的程序猿无法调用里面的显示函数来将图片显示到 MFC 的 Picture Co ...

  6. SSH框架之Struts(2)——Struts的执行流程之配置文件

    上篇我们大致了解了一下採用了Struts框架的web页面运行流程. 接下来的几篇我们通过Struts的源代码来学习一下Struts的内部原理. 当server启动的时候.server会依据配置文件初始 ...

  7. xtrabackup进行物理备份、恢复、在线克隆从库、在线重做主从

    http://www.lai18.com/content/4733997.html 注:图片来自<深入浅出MySQL 数据库开发 优化与管理维护 第2版> 物理备份和恢复 1.冷备份:停掉 ...

  8. Playing with ptrace, Part II

    Playing with ptrace, Part II Issue From Issue # December Dec , By Pradeep Padala inSysAdmin In Part ...

  9. LeetCode: Palindrome Partition

    LeetCode: Palindrome Partition Given a string s, partition s such that every substring of the partit ...

  10. VBA Excel 单元格操作

    1. 设置单元格边框: .Range("A3:M" & l + 1).SelectWith Selection.Borders() .LineStyle = xlConti ...