Tag: json

JSONasynchronous请求

我想使用asynchronous请求获取JSON数据,我正在通过syncrouns这样做,但现在需求是变化,但我无法修改此代码为asynchronous,因为我必须返回NSdata + (NSString *)stringWithUrl:(NSURL *)url { // if(kShowLog) NSLog(@"%@", url); NSURL *newURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@",url]]; NSURLRequest *urlRequest = [NSURLRequest requestWithURL:newURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:1]; // Fetch the JSON response NSData *urlData; NSURLResponse *response; NSError *error; // NSOperationQueue *opQueue; // Make synchronous request urlData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error]; return [[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding]; }

以JSON格式的string文件,如何将filecontent读入NSDictionary

我的应用程序包中只有一个文件“xyz.txt”,只有JSON格式的文本。 我想打开文本文件的文件path,并将内容读取到NSDictionary。 怎么做。 我已经准备好了我的JSONstring。 只需要启动到NSdictionary。 如果我直接在代码中初始化,那么在evey键和值之前,我会需要很多@。 我想避免这种情况。 这就是原因,我把JSON放在一个文件“xyz.txt” 我有两种方法 – 1.我读取表单文件,并使用[[NSDictionary alloc] initWithContentsOfFile:filePath]; 2.我把这个string分配给了NSDictionay。 我一直想避免使用@ 我知道我们可以通过NSData ID结果= [NSJSONSerialization JSONObjectWithData:数据选项:NSJSONReadingMutableContainers错误:&错误]; 但即使在这种情况下,我们将需要使用@初始化string到NSData的所有键和值。 任何解决scheme,可以从文本文件读取JSON和输出分配给NSDictionary { "ABC": [ { "id": "01", "score": "0.2" }, { "id": "02", "score": "0.2" } ], "XYZ": [ { "id": "01", "score": "0.9" }, { "id": "02", "score": "0.9" } ], "PQR": [ { […]

如何将JSON转换为NSArray

我有一个JSON数组在页面上输出。 我想将这个JSON数组转换成NSArray。 或者像这样转换这个json: 有人可以让我知道这一步可能是什么? 谢谢!

如何发送JSON格式的input嵌套在NSDictionary中的值

如果input一个简单的非嵌套值的代码是: $values = array('input_values' => array('input_1' => 'Testing', 'input_2' => 'Testing', 'input_3' => 'Testing',)); 而在Obj-C ,它将如下所示: NSDictionary *params = @{@"input_1": @"Testing", @"input_2": @"Testing", @"input_3": @"Testing"}; NSMutableDictionary *modify = [NSMutableDictionary new]; [modify setObject:params forKey:@"input_values"]; 那么我们如何在obj-C中转换和发送这个嵌套的代码呢? $forms = array( array( 'title' => 'API Generated 10', 'description' => 'This is the description', 'labelPlacement' => 'top_label', 'button' => array( […]

在parsing数据时发生iOS错误

在我的应用程序中,我使用JSONparsing数据 NSString * urlString=[NSString stringWithFormat:@"http://userRequest?userid=bala@gmail.com&latitude=59.34324&longitude=23.359257"]; NSURL * url=[NSURL URLWithString:urlString]; NSMutableURLRequest * request=[NSMutableURLRequest requestWithURL:url]; NSError * error; NSURLResponse * response; NSData *data=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; NSString * outputData=[[NSString alloc]initWithData:data encoding:NSASCIIStringEncoding]; NSLog(@"%@",outputData); SBJsonParser *jsonParser = [SBJsonParser new]; NSDictionary *jsonData = (NSDictionary *) [jsonParser objectWithString:outputData error:nil]; NSLog(@"%@",jsonData); NSInteger success = [(NSNumber *) [jsonData objectForKey:@"success"] integerValue]; 这段代码执行后,在我的日志中打印为 ({ latitude […]

在Swift中将JSON加载到UItableView中

我一直试图从JSON返回stringurl,并将其存储在数组中,然后在UITableView显示数组。 但它显示空的UILabel 。 class PhotosTableViewController: UITableViewController { let imageLoadURL = "https://…" var TAG_IMG_URL = [] verride func viewDidLoad() { super.viewDidLoad() getLatestPhotos() } override func numberOfSectionsInTableView(tableView: UITableView) -> Int { return 1 } override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return TAG_IMG_URL.count } override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { […]

如何使用iOS应用程序的Web服务器? 样本

我写了类似的问题,我回答了“如何使用iOS应用程序的Web服务器? 但我需要样本,因为它是更简单的,我有一些示例如何工作,例如,你可以帮助我的样本: 我怎么能实现请求在我的服务器exhample如果我想/注册新用户,我会收到服务器的答案在JSON中,我需要发送它variables'数据'POST? 对于exhample服务器是http://myserver.com:8080 。 { email: password: } //this is register form but how named this field? 我将会收到这样的答复: { result:[OK|fail] message: [error if fail] data: [if OK] } 我需要样本如何发送和接收/注册请求。 对不起,我的英文,它变得更好:) 更新我也不明白我怎么能在Objective-C中使用这个表单?

如何使用dynamicjson数据设置numberOfSectionsInTableView,titleForHeaderInSection

我有一些JSON数据给出下面,我想显示在一个表部分标题是部门,devise,雇员,发展,雇员。 我在numberOfSectionsInTableView , titleForHeaderInSection使用静态数据,但我想要使用dynamic数据。 我怎样才能做到这一点? { "Departments":[ { "name":"Designing", "id":"1.1", "Employees":[ { "name":"Ramesh", "id":"1.1.1", "salary":"4lakhs" }, { "name":"Suresh", "id":"1.1.2", "salary":"4lakhs" } ] }, { "name":"Developing", "id":"1.2", "Employees":[ { "name":"Ram", "id":"1.2.1", "salary":"4lakhs" }, { "name":"Sam", "id":"1.2.2", "salary":"4lakhs" } ] } }

parsing一个json数组会返回swift中的空元素

正如OOPer所build议的那样,我把它作为一个单独的问题发布。 这是这个的扩展: JSON序列化错误 我拉一个PHP脚本读取一个SQL数据库的JSON数组。 json非常大,但应该通过使用几个在线testing人员进行testing。 问题是,当我尝试从数组中获取元素返回nil。 它能够下载数据,并且可以正确地计算数组中有多less个元素,但是当我尝试访问这些元素时,它将返回nil。 有什么build议么? 这是一个元素的例子: { "id":2045, "oprettelsesdato":"09-02", "overskrift":"etc etc etc", "navn":"xyz xyz xyz", "tlf":"12345678", "email":"etc@etc.etc", "journal":"MJ", "intro":"yada yada yada yada ", "annonce":"test", "address":"testroad" }, LocationModel.swift import Foundation class LocationModel: NSObject { //properties var id: String? var oprettelsesdato: String? var overskrift: String? var address: String? var intro: String? var email: String? […]

Swift 3 – 在Safari中从JSON打开URL

我目前有一个移动应用程序,从JSON文件中带来的项目列表。 JSON文件也有附加到每个项目的URL列表。 当用户触摸列表视图中的项目时,我需要在Safari中打开URL。 override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) cell.textLabel?.text = TableData[indexPath.row] return cell } 有没有人有关于如何做到这一点的想法,我可以张贴代码来显示如何在必要时带入数据列表。