nsjsonserialization

iOS Send JSON data in POST request using NSJSONSerialization

淺唱寂寞╮ 提交于 2019-12-04 13:08:29
I know that there are similar questions posted as I have read though most all of them and still am having problems. I am trying to send JSON data to my server, but I do not think the JSON data is being received. I'm just not sure what I am missing. Below is my code... Method to send data to server. - (void)saveTrackToCloud { NSData *jsonData = [self.track jsonTrackDataForUploadingToCloud]; // Method shown below. NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; NSLog(@"%@", jsonString); // To verify the jsonString. NSMutableURLRequest *postRequest =

Serialize JSON string that contains escaped (backslash and double quote) Swift return Badly formed object

折月煮酒 提交于 2019-12-04 10:46:15
I have response string from the backend like this: { "status": "success", "data": "{\"name\":\"asd\",\"address\":\"Street 1st\"}" } I think the problem was because the double quote (") in the data String. When I remove the double quote, the serialization was success. But the response is from backend and I have to deal with it. Anyone can solve this problem? Thank you. Here is the playground code. import Foundation var jsonStr = """ { "status": "success", "data": "{\"name\":\"asd\",\"address\":\"Street 1st\"}" } """ let data = jsonStr.data(using: .utf8) if let d = data { do { let o = try

Valid JSON, but 'Cocoa error 3840' from AFNetworking/NSJSONSerialization

可紊 提交于 2019-12-04 05:49:55
I've been hacking away for hours trying to solve this problem to no avail - it seems like my only option is to post here to see if anyone can shed some light on this issue. It may be an issue with AFNetworking, or (more likely), it may be an issue with my code. The code I am using works perfectly for 99% of the operations within my application. I am developing an app that leverages Elastic Search by building JSON searches, sending them off and receiving a response from the server. Here is an example of the JSON that is returned: { "took": 4, "timed_out": false, "_shards": { "total": 5,

How can I return NSJsonSerialization

一笑奈何 提交于 2019-12-04 05:49:11
问题 First, I know nothing about Objective-C. That said the follow code should be getting the data from AsyncStorage . I've already did something like for Android where the basic idea is get the data from AsyncStorage as Json Object. What I need now, is use the jsonFromLocalRNStrogeForKey inside callInviteReceived jsonFromLocalRNStrogeForKey source +(void)jsonFromLocalRNStrogeForKey:(NSString *)key completion:(void (^)(NSDictionary * _Nullable, NSError * _Nullable))completion {

-[__NSCFDictionary objectAtIndex:]: unrecognized selector sent to instance 0x8943940 while parsing JSON Page to UITableView

大城市里の小女人 提交于 2019-12-04 04:58:14
问题 I have been through many links and fortunately I got many similar links but nothing worked Out. my array is appearing like this in Output, using NSLog().. products = ( { cid = 1; name = "hello world"; }, { cid = 2; name = "It is an array"; }, { cid = 3; name = "error error"; }, { cid = 4; name = "OMG! still same"; }, { cid = 5; name = "any help"; ... ... }, { cid = 130; name = "How is the work going on."; }, { cid = 131; name = "Had a nice lunch"; } ); success = 1 Code to parse JSON, where

Issue in converting NSDictionary to json string, replacing / with \\/

孤街醉人 提交于 2019-12-04 03:04:37
i want to convert NSDictionary to json string.everything is working fine, i have a small issue that is described as follows: I have a following code for conversion of NSDictionary to NSString: -(NSString *)dictToJson:(NSDictionary *)dict { NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil]; return [[NSString alloc] initWithBytes:[jsonData bytes] length:[jsonData length] encoding:NSUTF8StringEncoding]; } I am calling the method as: NSLog(@"%@", [self dictToJson:@{@"hello" : @"21/11/2014 10:07:42 AM"}]); following is the output of this

iOS JSON Parse not working (returns null dictionary)

主宰稳场 提交于 2019-12-04 02:48:29
I use the NSJSONSerialization 's JSONObjectWithData:data options: error: to parse JSON data returned from a server. Now for the options parameter I use: NSJSONReadingAllowFragments . You can look below and see the actual JSON (where I believe the problem is). The error message I get is: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Invalid value around character 0.) UserInfo=0x6895da0 {NSDebugDescription=Invalid value around character 0.} Any idea how to fix it? JSON = {"name":"Johan Appleseed", "email":"j.appleseed@emuze.co", "phone":"

How to convert NSDictionary to custom object

不问归期 提交于 2019-12-04 01:26:57
I have a json object: @interface Order : NSObject @property (nonatomic, retain) NSString *OrderId; @property (nonatomic, retain) NSString *Title; @property (nonatomic, retain) NSString *Weight; - (NSMutableDictionary *)toNSDictionary; ... - (NSMutableDictionary *)toNSDictionary { NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init]; [dictionary setValue:self.OrderId forKey:@"OrderId"]; [dictionary setValue:self.Title forKey:@"Title"]; [dictionary setValue:self.Weight forKey:@"Weight"]; return dictionary; } In string this is: { "Title" : "test", "Weight" : "32", "OrderId" : "55"

<extracting data from value failed> in NSDictionary

拥有回忆 提交于 2019-12-03 12:22:15
I am stuck at a point when I convert data from web services to NSDictionary. But while accessing on console in debug mode it returns , while when i bind the values of dictionary with view it works perfectly. Below is the code:- NSDictionary *responseDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&e]; and at console i am using po [dictName valueForKey:@"Status"] as well as po [dictName objectForKey:@"Status"] . Followed few steps but does not work for me 1. setting Optimization level to none already in this mode. 2.Edit scheme to debug mode already

How to serialize UIImage to JSON?

给你一囗甜甜゛ 提交于 2019-12-03 03:19:42
I am using imageData = UIImagePNGRepresentation(imgvw.image); and while posting [dic setObject:imagedata forKey:@"image"]; after NSData *data = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&theError]; now app is crashing Terminating app due to uncaught exception ' NSInvalidArgumentException ', reason: 'Invalid type in JSON write (NSConcreteMutableData) CodenameLambda1 You need to convert your UIImage to NSData and then convert that NSData to a NSString which will be base64 string representation of your data. Once you get the NSString* from NSData*, you