Questions tagged [nsjsonserialization]

NSJSONSerialization class is used to convert JSON to Foundation objects and Foundation objects to JSON

NSJSONSerialization class is used to convert JSON to Foundation objects and Foundation objects to JSON.

More information: NSJSONSerialization Class Reference

709 questions
13
votes
11 answers

Converting NSObject to NSDictionary

Hello I a class of type NSObject: ProductDetails *details = [[ProductDetails alloc] init]; details.name = @"Soap1"; details.color = @"Red"; details.quantity = 4; I want to pass the "details" object to a dictionary. I did, NSDictionary *dict =…
tech_human
  • 6,592
  • 16
  • 65
  • 107
12
votes
4 answers

Write a prettyPrinted JSON object with sorted keys in Swift

We often want to use JSON for human readability. As such, it is common to ask to sort the JSON keys alphabetically (or alphanumerically) in Go, in .NET, in Python, in Java, ... But how to output a JSON with JSON keys sorted alphabetically in…
Cœur
  • 37,241
  • 25
  • 195
  • 267
12
votes
4 answers

JSON Serialization crashing in swift

I had been using the following line of code to parse JSON data in Objective-C, but the same in Swift crashes the app. NSDictionary* json = [NSJSONSerialization JSONObjectWithData:_webData …
Jeswin
  • 238
  • 1
  • 3
  • 16
12
votes
6 answers

How to convert NSDictionary to custom object

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; ... -…
1110
  • 7,829
  • 55
  • 176
  • 334
11
votes
3 answers

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

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…
Jefferson Setiawan
  • 536
  • 1
  • 5
  • 22
11
votes
1 answer

Dictionary to JSON being serialised twice in swift 3

I'm trying to make a post request with the following dictionary which is converted to JSON let store = [ "newTask" : [ "project_name": "iOS", "total_time":0, "color":"blue" ] ] I am…
Sohil Pandya
  • 755
  • 1
  • 7
  • 19
11
votes
1 answer

in NSDictionary

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…
Anupam Gupta
  • 623
  • 1
  • 7
  • 18
11
votes
3 answers

NSJSONSerialization serialization of a string containing forward slashes / and HTML is escaped incorrectly

I am trying to convert some simple HTML into a string value in a JSON object and I'm having trouble getting the string encoding to not escape the string in NSJSONSerialization. Example... I have a string which contains some basic HTML text: NSString…
JasonD
  • 7,472
  • 5
  • 31
  • 31
9
votes
5 answers

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

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 { …
Faisal Ikwal
  • 703
  • 3
  • 8
  • 25
9
votes
2 answers

Invalid value around character 0, NSJSONSerialization

I make a get from my server and I get a valid response: - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { // Append the new data to the instance variable you declared //[_responseData…
ƒernando Valle
  • 3,634
  • 6
  • 36
  • 58
9
votes
2 answers

Objective-C: NSJSONSerialization floating point number issue

I'm using NSJSONSerialization to convert json string to NSDictionaray the JSON string is {"bid":88.667,"ask":88.704} after NSJSONSerialization { ask = "88.70399999999999"; bid = "88.667"; } Anybody know this issue?
damo
  • 849
  • 12
  • 16
9
votes
6 answers

iOS JSON Parse not working (returns null dictionary)

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…
byteSlayer
  • 1,806
  • 5
  • 18
  • 36
8
votes
4 answers

NSJSONSerialization

I have problems with some public json services with serveices formatted this way jsonFlickrFeed({ "title": "Uploads from everyone", "link": "http://www.flickr.com/photos/", "description": "", "modifi ...…
GAVELLO
  • 123
  • 1
  • 2
  • 4
8
votes
5 answers

Urban Airship crashes when calling takeoff

Upgrading to UrbanAirship 3.0.0 with Xcode 5.0, I'm getting an error when calling this code: [UAirship takeOff:config]; The error is +[NSJSONSerialization stringWithObject:]: unrecognized selector sent to class 0x3b2ca9fc 2013-09-19 15:02:31.981…
8
votes
1 answer

The Operation couldn't be completed. (Cocoa error: 3840.)

I am trying to parse JSON for an ios 6 app, but can't seem to get it to work. I have scoured tons of forums but haven't found a solution that works, that I understand enough to implement, or that applies. I apologize if there is one that I missed. …
dherrin79
  • 367
  • 1
  • 4
  • 13
1
2
3
47 48