json 读写 swift
//
// ViewController.swift
// json读写
//
// Created by mac on 15/7/14.
// Copyright (c) 2015年 fangyuhao. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
var json: AnyObject? = NSJSONSerialization.JSONObjectWithData(NSData(contentsOfURL: NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("obj", ofType: "json")!)!)!, options: NSJSONReadingOptions.allZeros, error: nil)
if let lang: AnyObject = json?.objectForKey("language") {
println(lang)
}
//生成
var dict = ["name":"jikexueyuan","age":1]
var jsonData = NSJSONSerialization.dataWithJSONObject(dict, options: NSJSONWritingOptions.allZeros, error: nil)
if let str = NSString(data: jsonData!, encoding: NSUTF8StringEncoding){
println(str)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
json 读写 swift的更多相关文章
- UE4 的json读写方式
转自:http://blog.csdn.net/cartzhang/article/details/41009343 JSON 的解析有很多开源库.UE4的JSON使用在代码的Public->S ...
- UE4的JSON读写方式<一>
声明:全部权利保留. 转载必须说明出处:http://blog.csdn.net/cartzhang/article/details/41009343 UE4的Json的解析博客地址: http:// ...
- UE4的JSON读写方式<一>
声明:所有权利保留. 转载必须说明出处:http://blog.csdn.net/cartzhang/article/details/41009343 UE4的Json的解析博客地址: http:// ...
- UE4的JSON读写方式<二>
声明:所有权利保留. 转载必须说明出处:http://blog.csdn.net/cartzhang/article/details/43794409 Json的Writer博客地址: http:// ...
- Python中异常和JSON读写数据
异常可以防止出现一些不友好的信息返回给用户,有助于提升程序的可用性,在java中通过try ... catch ... finally来处理异常,在Python中通过try ... except .. ...
- 文件读写 swift
// // ViewController.swift // 文件读写 // // Created by mac on 15/7/12. // Copyright (c) 2015年 fangyuhao ...
- UserDefault 用户首选项读写 swift
// // ViewController.swift // 首选项数据读写 // // Created by mac on 15/7/12. // Copyright (c) 2015年 fangyu ...
- golang json 读写配置文件
package main import ( "encoding/json" "fmt" "os" ) type configuration ...
- C# 使用Newtonsoft.Json读写Json文件
{ "CAN": false, "AccCode": 4294901856, "Id": 768, "BPointMove&quo ...
随机推荐
- ENVI二次开发模式下的Landsat数据读取
从usgs网站或者马里兰大学下载TM或Landsat原始数据,数据可能包括9个tif数据,两个txt文件和一个gtf文件.示例结构如下: ENVI下可以直接打开*_MTL.txt文件打开,打开后波段列 ...
- Java 单测 回滚
Java 在单测的时候 需要做回滚 设置如下: 需要添加以下 注解 在类上 defaultRollback = true : 为 默认全部回滚 defaultRollback = false : 为 ...
- Backup App's data without rooting the phone
First I'd like to let you know that my phone is Android 6.0 Marshmallow. So it works on the latest A ...
- Linux之文件系统的简单操作
df:列出文件系统整体硬盘使用量 将容量以易读方式显示: [root@zkero ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/s ...
- 获取本地ip地址
#import <ifaddrs.h> #import <arpa/inet.h> // Get IP Address - (NSString *)getIPAddress { ...
- windows 8.1 MessageDialog
private Popup p; private void Button_Click(object sender, RoutedEventArgs e) { p=new Popup(); Denglu ...
- (转载)前端构建工具gulp使用
前端构建工具gulp使用 前端自动化流程工具,用来合并文件,压缩等. Gulp官网 http://gulpjs.com/ Gulp中文网 http://www.gulpjs.com.cn/ Gulp中 ...
- WordPress 主题开发 - (十二) Search模板与Page模板 待翻译
The Search Template and The Page Template are vital to any complete WordPress Theme. And they're bot ...
- jquery中的mouseenter实现理解
说在前面:首先说一下两者之间的区别,假设当前元素为element,mouseover事件具有冒泡特性,也就是说无论鼠标是从别的元素移动到element或者是从element的子元素移动到element ...
- Creating an API-Centric Web Application[转]
Creating an API-Centric Web Application 转自 http://hub.tutsplus.com/tutorials/creating-an-api-centric ...