Tag: json

如何快速parsingJson对象3

您好我的问题是关于json对象。 我有这个链接“ http://ip-api.com/json ”,这个链接给出了你的IP地址的详细信息。 我只需要从这个json文件打印IP地址在swift 3.我很新可能是我的问题是基本的,但我需要一些帮助来整理我的项目。 所以我做了如下。 let requestURL: NSURL = NSURL(string: "http://ip-api.com/json")! let urlRequest: NSMutableURLRequest = NSMutableURLRequest(url: requestURL as URL) let session = URLSession.shared let task = session.dataTask(with: urlRequest as URLRequest) { (data, response, error) -> Void in let httpResponse = response as! HTTPURLResponse let statusCode = httpResponse.statusCode if (statusCode == 200) { print("Everyone […]

如何在Swift中使用Alamofire将发送数组的字典(JSON格式)发送到服务器3

我试图创build和发送字典JSON格式的数组Alamofire。 { "attendance": [{ "attndid":"0", "psngrtype": "student", "date":currentdate, "cuid": "25", "enttid": "21", }] } 在这里,我使用了tableview,在上面的“cuid”&“enttid”中我给出了可选的tableview单元格数据的值。 剩下的是不变的。 我传递一个字典数组,如果我select一个tableview单元格数据。 和两个数组,如果我select两个cells.etc ..和我使用下面的代码,我得到但得到问题创build字典格式。 我的代码: let arrayOfDictionaries: [[String:AnyObject]] = [ ["psngrtype":"student" as AnyObject, "attndid": "0" as AnyObject , "cuid":stdpasngerid as AnyObject, "enttid": entitID as AnyObject, "attnddate":CurrentDate as AnyObject ]] print(arrayOfDictionaries.toJSONString()) extension Collection where Iterator.Element == [String:AnyObject] { func toJSONString(options: JSONSerialization.WritingOptions […]

当使用谷歌方向Api和请求数据在JSON获取零数据

我是新手,编程和iOS开发与迅速。 我试图在两个地点之间映射一条路线,并遇到了这个问题。 func getDirections(origin: String!, destination: String!, waypoints: Array<String>!, travelMode: AnyObject!, completionHandler: ((status: String, success: Bool) -> Void)) { if let originLocation = origin { if let destinationLocation = destination { var directionsURLString = baseURLDirections + "origin=" + originLocation + "&destination=" + destinationLocation directionsURLString = directionsURLString.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)! let directionsURL = NSURL(string: directionsURLString) dispatch_async(dispatch_get_main_queue(), { () -> […]

RestKit映射与NSDictionary和NSArray对象

{"coord":{"lon":72.62,"lat":23.03},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10n"}],"base":"stations","main":{"temp":303.082,"pressure":1014.85,"humidity":66,"temp_min":303.082,"temp_max":303.082,"sea_level":1018.46,"grnd_level":1014.85},"wind":{"speed":1.07,"deg":340.501},"rain":{"3h":0.435},"clouds":{"all":76},"dt":1475333911,"sys":{"message":0.0033,"country":"IN","sunrise":1475283682,"sunset":1475326567},"id":1279233,"name":"Ahmadabad","cod":200} 以上是我的API响应。 现在我想映射“天气”和“名称”,并希望同一个对象作为响应。 我可以创build上课 @interface WeatherStatus : NSObject @property (nonatomic, copy) NSString *name; @property (nonatomic, strong) WeatherInfo *info; @end 和 @interface WeatherInfo : NSObject @property (nonatomic, copy) NSString *description; @property (nonatomic, copy) NSString *icon; 下面是映射代码。 RKObjectMapping *weatherInfo = [RKObjectMapping mappingForClass:[WeatherInfo class]]; [weatherInfo addAttributeMappingsFromDictionary:@{@"description": @"description", @"icon": @"icon"}]; RKObjectMapping *weatherStatus = [RKObjectMapping mappingForClass:[WeatherStatus class]]; [weatherStatus addAttributeMappingsFromArray:@[@"name"]]; […]

大型数据库 – 在设备上显示数据的最佳方式?

我目前正在创build一个iOS应用程序,该应用程序连接到数据库,并asynchronous下载数据的JSON对象以显示在表格视图中。 就目前来看,这是一个好方法。 但是,当数据库开始变大时,这会造成很大的不便。 我在Objective-C方面非常熟练,但在数据库方面并不那么重要。 从服务器获取这些数据并将其保存在应用程序中的最佳方式是什么? 目前,我有一个自定义类对象存储JSON对象中的每个“对象”的数据。 然而,数据库将处理应用程序的许多其他方面,如邀请,login和用户详细信息。 核心数据是否会走? 即复制数据库(在一定程度上)并将其存储在本地,然后从那里访问。 正如我所说,我不太确定采取哪条路线,所以任何build议都会得到真正的赞赏。

Swift可解码的可选键

(这是这个问题的一个后续: 使用具有多个键的可解码协议 。) 我有以下的Swift代码: let additionalInfo = try values.nestedContainer(keyedBy: UserInfoKeys.self, forKey: .age) age = try additionalInfo.decodeIfPresent(Int.self, forKey: .realage) 我知道,如果我使用decodeIfPresent并没有该属性,它仍然会正确处理它,如果它是一个可选的variables。 例如,下面的JSON使用上面的代码来parsing它。 { "firstname": "Test", "lastname": "User", "age": {"realage": 29} } 而下面的JSON也适用。 { "firstname": "Test", "lastname": "User", "age": {"notrealage": 30} } 但以下不起作用。 { "firstname": "Test", "lastname": "User" } 我怎样才能使所有3个例子工作? 对于nestedContainer有没有类似nestedContainer ?

使用GoogleCast-SDK v3从ios发件人发送JSON到receiver-app

我正在使用Google-Cast-SDK v3开发ios发件人和自定义接收器应用程序。 我似乎无法find发送包含JSON的消息到Receiver-App的适当方法。 我必须使用sendTextMessage函数吗?还是有更好的方法? 这个“新”function将能够发送一个base64编码图像? (后端没有真正的文件pipe理,这是我现在可以使用的所有东西。) 感谢您的回答

IOS使用SDWebImage从URL加载图像

我尝试从下面的json URL加载图像,但我得到了[cell.imageView setImageWithURL:[NSURL URLWithString:@"coffeemugDirectLink"] placeholderImage:[UIImage imageNamed:@"heart.png"]]; 错误是Expected ',' separator和Expected expression in container literal我做错了什么? 我怎样才能从JSON加载到UICollectionView我的单元格的URL? import UIKit import SDWebImage class TopratedVC: BaseViewController { @IBOutlet var collectionview: UICollectionView! @IBOutlet var Image: UIImageView! //Our web service url let URL_GET_coffeemugs:String = "http://coffeemugs.com/ios/feed.php" override func viewDidLoad() { super.viewDidLoad() addSlideMenuButton() // Do any additional setup after loading the view. //SDWebimage stuff […]

当通过Objective C调用时,Web服务方法不会被命中

我的App_Code / IGetEmployees.vb文件 <ServiceContract()> _ Public Interface IGetEmployees <OperationContract()> _ <WebInvoke(Method:="POST", ResponseFormat:=WebMessageFormat.Json, BodyStyle:=WebMessageBodyStyle.Wrapped, UriTemplate:="json/contactoptions")> _ Function GetAllContactsMethod(strCustomerID As String) As List(Of NContactNames) End Interface 我的App_Code / GetEmployees.vb文件 <WebMethod()> _ <ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _ Public Function GetAllContactsMethod(strCustomerID As String) As List(Of NContactNames) Implements IGetEmployees.GetAllContactsMethod Utilities.log("Hit get all contacts at 56") Dim intCustomerID As Integer = Convert.ToInt32(strCustomerID) Dim lstContactNames […]

绑定Json和post请求

经过了一整天,并检查堆栈溢出和几个论坛上的许多链接,我无法破解它:我认为许多swift开发人员发现它很容易,但我无法破解它,请帮助 我有一个url和一个JSON来绑定和获取JSON响应 urlPOST: http://myurl/myurl.com…….// JSON请求: { "BookingId": "1501433021", "ProductType": "0", "Client": "1", "OriginAirport": { "CityCode": "NYC", "CityName": "New York", "AirportCode": "NYC", "AirportName": "New York City All Airports", "Country": "US", "Terminal": "" }, "DestinationAirport": { "CityCode": "LON", "CityName": "London", "AirportCode": "LON", "AirportName": "London All Airports", "Country": "GB", "Terminal": "" }, "TravelDate": "2016-10-19T05:07:57.865-0400 ", "ReturnDate": "2016-10-21T05:08:02.832-0400 ", […]