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
4
votes
2 answers

Canonicalize JSON so equivalent objects have the same hash

I'm storing JSON objects in a database. Many—perhaps most—of these objects will be duplicates, so I would like to key them on something like a SHA hash to avoid creating unnecessary extra records. The problem is, at the point where I want to write…
Becca Royal-Gordon
  • 17,541
  • 7
  • 56
  • 91
4
votes
2 answers

How to handle NSJSONSerialization's crashing when disconnected to internet

I implement web service in my app. My way is typical. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { //Web Service xxx,yyy are not true data NSString *urlString = …
bc a
  • 117
  • 2
  • 9
4
votes
1 answer

iOS: NSJSONSerialization results in "data paremeter is nil'

I had the NSURLConnection and all the appropriate methods working in one view controller. Then i moved it to a UICollectionViewController and get an exception below - (void)connectionDidFinishLoading:(NSURLConnection *)connection { NSError…
Matthew
  • 2,035
  • 4
  • 25
  • 48
4
votes
1 answer

Creating an object that works with NSJSONSerialization dataWithJSONObject:options:error:

At the moment in order to use this function I'm "converting" my object into a dictionary. i.e. the property names become the keys and the property values become the values. Is there a way to properly do this so that an object will work with this…
Fogmeister
  • 76,236
  • 42
  • 207
  • 306
4
votes
4 answers

iOS - NSJSONSerialization: Unable to convert data to string around character

I'm getting this error while parsing JSON: NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error]; Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed.…
Oleg
  • 2,984
  • 8
  • 43
  • 71
4
votes
1 answer

Is NSJSONSerialization more error-tolerant and robust than JSONKit?

Although according to benchmarks JSONKit is faster, the Github readme is full of warnings that illformed JSON leads to crashes, etc. For me it is more important that there is no crash, and that an ilformed Unicode JSON or other subtle error in the…
Proud Member
  • 40,078
  • 47
  • 146
  • 231
3
votes
1 answer

NSJSONSerialization leaks in Callback Block

I'm trying to use Blocks as callbacks for an API request via the method below. This method takes a Block that is nested in this method's Block. It works... BUT, If an Object that has called this method is dealloced, NSJSONSerialization dumps out a…
3
votes
1 answer

Guid does not get transferred to service correctly using ASP.NET Core web service

I have the following problem: I have an IDto interface and a Dto base class implementing said interface. The base class overrides an id and a ManualId which are defined in the HasId base class. Then I also have an AuthorDto which inherits from the…
3
votes
1 answer

Swift Escaping Unwanted Backslash Characters on JSON Encoding

I’m getting a bunch of unneeded “escaped back-slash” characters when I convert my Swift Dictionary object using JSONSerialization. It’s only happening on one of my Key-Value pairs - the one that has a URL in it: "image" :…
Sirab33
  • 1,247
  • 3
  • 12
  • 27
3
votes
0 answers

Unhandled Exception: type '_InternalLinkedHashMap' is not a subtype of type 'Map'

i am trying to use a json into another json but getting this error " Unhandled Exception: type '_InternalLinkedHashMap' is not a subtype of type 'Map'" i am using jsonserializable this is my data file i want to use it in product file import…
Lalit Rawat
  • 1,022
  • 2
  • 17
  • 39
3
votes
2 answers

NSDictionary to Json in Xamarin.iOS

I am trying to convert the NSDictionary into Json using NSJsonSerialization.Serialize. But i am not getting expected output Code in Xamarin.iOS var dictionary = new NSDictionary( new NSString("userName"), new NSString("450012"), …
Hunt
  • 8,215
  • 28
  • 116
  • 256
3
votes
2 answers

Swift 4: Keeping the same order when parsing a JSON

I need to show a list of addresses in my app while keeping the same order as the response JSON. It looks something like this: { "addresses": { "e5fdb5ba-7afb-11e8-bead-43321d1a8905": { "contact": "Name1", "zipCode": "06100" …
MVZ
  • 2,220
  • 5
  • 27
  • 57
3
votes
1 answer

SendGrid API Request in Swift with URLSession

I'm trying to send a request to the SendGrid API using Swift 4 and URLSession. My hope is to not include any third-party dependencies since this is the only place in my app where I use JSON and an HTTP request. Since SendGrid doesn't have any Swift…
Clifton Labrum
  • 13,053
  • 9
  • 65
  • 128
3
votes
2 answers

Convert swift object (with nested objects) to JSON data in a pure Swift 3 way

I am trying to convert a swift object to JSON, I have seen these SO questions 1 & 2, but I could not apply it to my code. I have a swift object of type [String : DailyTimes] which I would like to convert it back to JSON data in a pure Swift 3 way,…
SpaceX
  • 2,814
  • 2
  • 42
  • 68
3
votes
3 answers

Swift Error: ambiguous reference to member 'jsonObject(with:options:)

I am trying to load images from server into my iOS app with the help of GET request. However, it reports the error: ambiguous reference to member 'jsonObject(with:options:) Can anyone please help resolve the error? import UIKit class…