Tag: json

如何从NSDictionary中删除空值

我有一个JSON Feed: { "count1" = 2; "count2" = 2; idval = 40; level = "<null>"; "logo_url" = "/assets/logos/default_logo_medium.png"; name = "Golf Club"; "role_in_club" = Admin; } 问题是"<null>" ,我不知道如何将其保存到NSUserDefaults之前从NSDictionary中删除。 请帮我解决这个问题。 谢谢!

Restkit json来自服务器的错误响应信息

我已经用了很多时间来解决这个问题。 我使用Restkit 0.9.3与对象映射2.0。 所有的数据都是JSON。 我可以正确地进行GET,POST,PUT和DELETE操作,它是我不会捕获和映射的响应体。 所以我的问题是,我的宁静API是返回错误时出现问题。 我想用restkit映射这些错误,fx返回这个错误: {“code”:“401”,“message”:“未经授权”} 我如何映射这个JSON正确? 我已经尝试了很多东西,可以使用一些指导 – 或者请举一个例子。

如何用SwiftyJSONparsingstring数组?

如何使用SwiftyJSON将下面的JSON数组parsing为Swift [String] ? { "array": ["one", "two", "three"] } 我已经试过这个代码,但它不适合我: for (index: String, obj: JSON) in json["array"] { println(obj.stringValue) } 什么是处理这个最好的方法? 谢谢。

如何使用SwiftyJSON循环JSON?

我有一个我可以用SwiftyJSONparsing的json: if let title = json["items"][2]["title"].string { println("title : \(title)") } 完美的作品。 但我无法循环。 我试了两种方法,第一种是 // TUTO : //If json is .Dictionary for (key: String, subJson: JSON) in json { … } // WHAT I DID : for (key: "title", subJson: json["items"]) in json { … } XCode不接受for循环声明。 第二种方法: // TUTO : if let appArray = […]

在SWIFT中cachingJSON API的最佳方法是什么?

我需要caching来自API的json数据。 所以我研究了很多并得到这个post 。 我试图在我的应用程序中实现选项1。 但海关经理总是返回零。 我不知道为什么? 之后,我得到了AwesomeCache 。 它说这是一个真棒APIcaching。 但是我不知道如何实现呢? 我提到这个问题 。 我仍然无法弄清楚。 这是我的当前实现看起来没有caching: Alamofire.request(.GET, "http://api.androidhive.info/volley/person_array.json") .responseJSON { (_, _, data, _) in let json = JSON(data!) let catCount = json.count for index in 0…catCount-1 { let name = json[index]["name"].string println(name) } 请build议我从API中cachingJSON的最佳方法? 提前致谢! UPDATE 这些是我的要求 从API获取JSON并parsingJSON数据。 这些可以在Alamofire&SwiftyJSON的帮助下完成 我将在表视图中填充parsing的数据。 它在用户在线时有效。 但是我也想在用户离线时在表格中显示数据。 所以我需要保存parsing数据或JSON数据在我的caching中,我需要在一周或几天内刷新或过期caching。 我不喜欢将JSON存储在我的磁盘中,因为它将被更新。 请build议我最好的方法来实现这个…

问题:在iOS中将对象转换为json

我有一个名为“Store”的主要实体类,如: Store.h: – #import <Foundation/Foundation.h> #import "SignIn.h" @interface Store : NSObject @property (nonatomic, retain) NSString *storeId; @property (nonatomic, retain) NSString *storeProfileId; @property (nonatomic, retain) NSString *storeName; @property (nonatomic, retain) NSString *storeRegion; @property (nonatomic, retain) SignIn *signIn; @end Store.m: – #import "Store.h" @implementation Store @synthesize storeId, storeProfileId, storeName, storeRegion, signIn; – (id) initWithCoder: (NSCoder *)coder { […]

转换为swift后模糊使用“下标”2.3

转换到swift 2.3后,我得到了这个错误。 guard let json = try NSJSONSerialization.JSONObjectWithData(data!, options: []) as? NSDictionary else { throw JSONError.ConversionFailed } guard let loadedWeather = json["weather"]![0]["description"] as? String, let loadedTemperatur = json["main"]!["temp"] as? Float, let loadedWindSpeed = json["wind"]!["speed"] as? Float else { print("Weather JSON-Parsing failed") return } Ambiguous use of subscript错误的Ambiguous use of subscript来自声明“loadedWeather,loadedTemperatur和loadedWindSpeed”。 已经尝试将NSDictionary更改为字典和其他的东西,帮助在代码中的另一个位置,但在这里…. 多谢你们

如何收集使用NSDictionary嵌套在数组中的JSON数据

我有以下JSON: { 0: 200, error: false, campaigns: { current_campaigns: [ { id: "1150", campaign_type_id: "1", campaign_type: "Type", title: "Name (with type) ", url: "http://www.example.com", special: null, campaign_instructions: "Here's what you do", pay_description: "", start: "2013-10-14 00:00:00", end: "2014-03-31 23:59:59" }, { id: "1151", campaign_type_id: "1", campaign_type: "Type", title: "Name (with type) ", url: "http://www.example.com", special: […]

如何使用来自JSON文件的信息填充数组并计算距离?

我有一个JSON文件在这里: { "People": [{ "A1": "New York", "B1": "ShoppingMall1", "C1": "43.0757", "D1": "23.6172" }, { "A1": "London", "B1": "ShoppingMall2", "C1": "44.0757", "D1": "24.6172" }, { "A1": "Paris", "B1": "ShoppingMall3", "C1": "45.0757", "D1": "25.6172" }, { "A1": "Bern", "B1": "ShoppingMall4", "C1": "41.0757", "D1": "21.6172" }, { "A1": "Sofia", "B1": "ShoppingMall5", "C1": "46.0757", "D1": "26.6172" } ] […]

SBJsonparsing后执行(__NSArrayM objectForKey :)

我有一些问题试图parsingJSON使用SBJson,我做了一些研究,我找不到有帮助的… 我跟着一些关于如何做的博客,但是我仍然得到这个错误:“__NSArrayM objectForKey:” 所以这是我试图parsing的Json: { "result": [ { "authors": [ "Eric Ries" ], "bc": 9780671607, "title": "Yeah", "urlImage": "www.yeah.hey", "description": "Hey…" } ] } 这是我正在使用的代码: SBJsonParser *json; NSDictionary *jsonResults; NSError *jsonError; json = [ SBJsonParser new ]; // Get result in a NSDictionary jsonResults = (NSDictionary*) [ json objectWithString:output error:&jsonError ]; // Check if there […]