nsjsonserialization

How to hit post request with NSDictionary as parameter

橙三吉。 提交于 2019-12-11 18:54:42
问题 I am trying to hit post type sending dictionary as parameter. Below is what i tried so far, but i think format sending is not generating correctly. Please guide, code is below: Data fetching which need to send as parameter: NSArray *routesLegsArray = [[[[[json objectForKey:@"routes"]objectAtIndex:0] objectForKey:@"legs"] objectAtIndex:0] objectForKey:@"steps"]; NSMutableArray *arrSteps = [[NSMutableArray alloc] init]; for(int i=0; i<[routesLegsArray count]; i++) { if ([routesLegsArray count]

How to create model classes using JSONModel?

我怕爱的太早我们不能终老 提交于 2019-12-11 16:26:46
问题 I am trying to create Model Class by using JSONModel.My json Dictionary after using NSJSONSerialization looks like below. { apiStatus = { message = SUCCESS; success = 1; }; boardingPoints = "<null>"; inventoryType = 0; seats = ( { ac = 0; available = 1; bookedBy = "<null>"; commission = "<null>"; fare = 1200; }, { ac = 0; available = 1; bookedBy = "<null>"; commission = "<null>"; fare = 1200; }, ); } The JSON looks like this: {"boardingPoints":null,"inventoryType":0,"apiStatus":{"success"

Parse JSON Data Array with Swift 4

醉酒当歌 提交于 2019-12-11 15:19:51
问题 I am using the following code. It only works if the JSON data does not start with a '[' character. It works fine for JSON data starting with a '{' character. There is a similar question here: Parsing JSON array in swift but most of the methods are deprecated and I was unable to get the code to work. Here is the JSON call I am using: guard let json = (try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.mutableContainers)) as? [String: Any] else { print(

objective c calling wcf rest service request

亡梦爱人 提交于 2019-12-11 14:11:10
问题 I've been trying to look for online articles / tutorials on how to go about coding a request from a wcf service. I have the following web service uploaded to my server: [ServiceContract] public interface IUserAccountService { [OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "UserLogIn?id={email}&password={password}")] AuthenticationToken UserLogIn(string email, string password); } I'm getting really confused with the articles or SO questions

ERROR happened while deserializing the JSON data

人走茶凉 提交于 2019-12-11 05:29:36
问题 -(void) conn:(NSString *)method{ dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_async(concurrentQueue, ^{ __block NSDictionary *resultBlock = nil; dispatch_sync(concurrentQueue, ^{ /* Download the json here */ //Create webservice address NSString *webService = [_baseURL stringByAppendingString:_webService]; //NSLog(@"%@", webService); //Create error object NSError *downloadError = nil; //Create the request NSMutableURLRequest *req =

Invalid top-level type in JSON write

半城伤御伤魂 提交于 2019-12-11 00:04:59
问题 I'm trying to create a simple JSON object but I still get error and I know what's wrong in my code: NSString *vCard = [BRContacts getContacts]; // this is just a string, could be nil NSDictionary *JSONdic = nil; if (vCard) { JSONdic = [NSDictionary dictionaryWithObjectsAndKeys:@"1",@"status",vCard,@"data", nil]; } else { JSONdic = [NSDictionary dictionaryWithObjectsAndKeys:@"0",@"status",@"vCard is empty",@"error", nil]; } NSError *error = nil; NSData *JSONData = [NSJSONSerialization

NSJSONSerialization unboxes NSNumber?

前提是你 提交于 2019-12-10 21:53:55
问题 I'm using NSJSONSerialization to turn a JSON document into the Core Foundation types. I have a field in my JSON which is a "number". It's sometimes and integer, sometimes a float. Now, the problem is when NSJSONSerialization turns my JSON into an NSDictionary and I try to extract the number using objectForKey, sometimes it's an int, and sometimes it's a double. It seems NSJSONSerialization doesn't simply leave it in an NSNumber wrapper, but actually unboxes the value, and inserts that into

NSInvalidArgumentException - 'Invalid top-level type in JSON write' - Swift

无人久伴 提交于 2019-12-10 14:56:34
问题 As mentioned in the title of post,I'm getting NSInvalidArgumentException - 'Invalid top-level type in JSON write' when trying to convert Dictionary to JSON Data in swift let userInfo: [String: String] = [ "user_name" : username!, "password" : password!, "device_id" : DEVICE_ID!, "os_version" : OS_VERSION ] let inputData = jsonEncode(object: userInfo) . . . static private func jsonEncode(object:Any?) -> Data? { do{ if let encoded = try JSONSerialization.data(withJSONObject: object, options:[])

Create json string from core data and vice versa?

China☆狼群 提交于 2019-12-10 12:15:34
问题 I have got entities in core data with one to many relationship. How can I convert data in my entities to json string and populate core data entities with json string once it is created? Any help would be greatly appreciated... 回答1: for core data to json: fetch the data from your coredata according to your requirements, & then converts it into json. visit this link to core data to json also see this one for json to core data 1)convert JSON to native Cocoa data types (NSDictionary and NSArray)

How to parse Dictionary with keys that have array of dictionaries

我的梦境 提交于 2019-12-10 11:19:06
问题 UPDATE-8/31/12- So now I would need to go through the Array of Dictionaries based on "isReservable" = 1 and then display the "begin". I am just trying to get the contents of the array of each dictionary and I can go from there (for now). Below is what I have tried. Thanks to everyone for the help I am learning more everyday. json from php page { "slots": { "2012-08-31 00:00:00 America/Los_Angeles": [ { "isPending": false, "isReservable": true, "isReserved": false, "label": " ", "begin": "2012