Tag: json

如何从嵌套的JSON获取值 – Objective c

我想从下面嵌套的JSON响应中获得一些键和值。 下面我提到了我的JSON响应结构,我需要从下面的响应中获取所有的keys(Red, Green)和键值values(Color and ID) ,并加载到Array for tableview单元格值。 仅供参考:我已经尝试了使用NSDictionary但我得到所有的时间无序的价值观。 我还需要获得有序的值。 请帮帮我! { response: { RED: { Color: "red", color_id: "01", }, GREEN: { Color: "green", color_id: "02", } }, Colorcode: { }, totalcolor: "122" } 我的代码: NSError *error; NSDictionary *jsonDictionary = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error]; NSArray *responsData = [jsonDictionary objectForKey:@"response"]; NSLog("%@",[responsData objectAtIndex:0]); // here I […]

如何在iOS中发送asynchronous发布请求

我需要一些LoginViewController帮助。 基本上我有一个小应用程序,我需要发布一些数据到应用程序,我新来的POST和JSON。 如果我能得到一些帮助和理解,将不胜感激。 以下是一些要求即时通讯工作。 我的.m文件标记为LoginViewController。 这是我迄今为止 -(void)setRequest { #pragma mark NSURLConnection Delegate Methods – (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { // A response has been received, this is where we initialize the instance var you created // so that we can append data to it in the didReceiveData method // Furthermore, this method is called each […]

如何从iOS中的这些json对象创build一个json数组

我有一本像这样的字典。 NSDictionary *dict = @{@"cpu" : self.proData , @"date" : timeMilliString, @"memory" : self.memData, @"battery" : self.batData, @"deviceID" : @"1" }; 我从这样创buildjson对象: self.jsonObj1 = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error]; self.jsonObj2 = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error]; self.jsonObj3 = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error]; 之后,我想把3个json对象放到一个json数组中,然后把这个json数组放到另一个json对象中。 最后,它应该看起来像这样: {"mobileData":[ { "cpu":-991, "date":"142441374.5834", "memory":978, "battery":-96, "deviceID" : 2 }, { "cpu":-51, "date":"142441374.5834", […]

Objective C从URL中读取JSON到NSDictionary中

因此,我正在制作一个获取用户当前位置的应用程序,然后将纬度和经度坐标发送到此URL以查看附近的所需商店。 我能够做我刚刚提到的一切,但不知道如何阅读网页内容的内容,并用它来形成一个表格视图/按最短距离排列等我做了一些研究,并计算出这是JSON,并设法parsingURL中的内容到NSJSONSerialization NSDictionary。 我不确定的是如何读取包含JSON语法的NSDictionary的内容。 我需要像“名称”,“距离”,“格式化地址”的键,并按照sorting的“距离”按升序排列我的数据在一个UITableView。 以下是我从URL获取的JSON脚本的屏幕截图:

如何在Swift中获取JSON数据并将其添加到URL

我如何获取JSON数据并将其添加到URL? 我的情况是我会访问JSON的URL,但我需要从其他JSON的URL值。 这是我的Json,我需要一个令牌来访问它。 https://api-sandbox.tiket.com/flight_api/all_airport/token= …… 要获取令牌,我必须从其他JSON访问,这个视图的另一个JSON来获取令牌。 {“diagnostic”:{“status”:200,“elapsetime”:“0.2082”,“memoryusage”:“16.99MB”,“unix_timestamp”:1499832598,“confirm”:“success”,“lang” ,“currency”:“IDR”},“output_type”:“json”,“login_status”:“false”,“token”:“ b650fce732668b58b0a4c404b65932e972ad123d ”} 我必须获取价值标记,并将其添加到第一个JSON URL来访问第一个JSON 这我的编码: func getLatestKotaTujuan(){ var tujuanUrl = URLComponents(string: "https://api-sandbox.tiket.com/flight_api/all_airport?")! tujuanUrl.queryItems = [ URLQueryItem(name: "token", value: "4d4bba355bb920fbdc1aa3848769a59ba74ea03c" ), URLQueryItem(name: "output", value: "json") ] let request = tujuanUrl.url let task = URLSession.shared.dataTask(with: request!, completionHandler: { (data, response, error) -> Void in if let error = error […]

如何在IOS中为这个Json响应dynamic创build可变字典

这是我的JSON响应1的时间inputSpent_on:“2015-12-27” { "A": { "user": { "id": 1, "name": "B" }, "startday": "2015-12-27", "status": "New", "total": 2, "time_entries": [{ "id": 768, "project": { "id": 8, "name": "C" }, "user": { "id": 1, "name": "B" }, "activity": { "id": 8, "name": "D" }, "hours": 2, "comments": "", "spent_on": "2015-12-27" }] } } 我已经创build了这样的字典格式来做后期操作: NSDictionary * response […]

如何parsing表视图上的API响应?

我的JSON响应数据合成为: – [{"0":"1","id":"1","1":"Pradeep","name":"Pradeep","2":null,"sender":null,"3":null," 所以parsing表视图上的“名称”? 我自己的实现是: 我是新的ios开发请帮助我 -(void)connectionDidFinishLoading:(NSURLConnection *)connection { NSDictionary *allDataDictionary=[NSJSONSerialization JSONObjectWithData:webData options:0 error:nil]; // response saved in allDataDictionary NSDictionary *feed=[allDataDictionary objectForKey:@"feed"]; // feeds entry NSArray *feedforentry=[feed objectForKey:@"entry"]; for(NSDictionary *diction in feedforentry) { NSDictionary *title=[diction objectForKey:@"title"]; NSString *label=[title objectForKey:@"label"]; [array addObject:label]; } [[self JustConfesstable]reloadData]; // reload table }

终止应用程序,由于未捕获的exception“NSRangeException”,原因:'*** – :索引0超出空数组的边界'

我正在开发使用Web服务的应用程序我得到这样的错误是这样的,当我testing真实的设备时,但是当我运行视网膜3.5模拟器,它完美的作品,请帮助我我已经尝试,但我不能解决这个问题。 Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array' *** First throw call stack: (0x30b59fd3 0x3b308ccf 0x30a9081b 0xeec19 0x334a8917 0x3344fc47 0x3344f49d 0x33375d79 0x32ff362b 0x32feee3b 0x32feeccd 0x32fee6df 0x32fee4ef 0x33379401 0x30b2525b 0x30b2472b 0x30b22f1f 0x30a8df0f 0x30a8dcf3 0x35992663 0x333d916d 0x100ec1 0x3b815ab7) libc++abi.dylib: terminating with uncaught exception of type NSException […]

Json值失败了ios

您好parsingJSON格式的URL,如下所示的错误 JSONValue failed. Error trace is: ( "Error Domain=org.brautaset.JSON.ErrorDomain Code=5 \"Unescaped control character '0xa'\" UserInfo=0x1d224220 {NSLocalizedDescription=Unescaped control character '0xa'}", "Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \"Object value expected for key: Location\" UserInfo=0x1d2242d0 {NSUnderlyingError=0x1d224260 \"Unescaped control character '0xa'\", NSLocalizedDescription=Object value expected for key: Location}", "Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \"Expected value while parsing array\" UserInfo=0x1d224310 {NSUnderlyingError=0x1d2242f0 \"Object value expected for key: […]

我怎样才能parsing每个项目到它的uicollection视图单元格

所以下面是我的parsingJSON并将其放入一个集合视图单元格的代码 import UIKit let cellId = "cellId" struct AnimeJsonStuff: Decodable { let data: [AnimeDataArray] } struct AnimeLinks: Codable { var selfStr : String? private enum CodingKeys : String, CodingKey { case selfStr = "self" } } struct AnimeAttributes: Codable { var createdAt : String? var slug : String? let synopsis: String? private enum CodingKeys : […]