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

Using NSJSONSerialization for mac

I'm trying to user NSJSONSerialization in a mac app, but i can't get it working, I'm trying to get it to load UserTimeline, and just show the text of the last tweet, and thats it, but I can't seem to find the proper way to use it. the api i have…
Alex Trott
  • 4,576
  • 4
  • 23
  • 30
2
votes
1 answer

NSJSONSerialization Not Creating Key Value Pairs

I am using iOS 5 new feature to parse JSON and I have no idea that why I am not getting any key value pairs. "aStr" (string representation of data) is putting the right JSON on the output window but I am getting nothing in "dicData" and there is no…
Leo
  • 1,547
  • 3
  • 24
  • 40
2
votes
1 answer

Swift / Combine JSON decodable - decode and receive array of content only 'Invalid top-level type in JSON write'

I am receiving some JSON which looks like the below : { "template": "search", "item": "2", "contents": [ { "title": "title 1", "subtitle": "subtitle 1", "imageurl":…
jat
  • 183
  • 3
  • 14
2
votes
2 answers

_TypeError (type 'List' is not a subtype of type 'Map

need your help resolving this error in Flutter...also how to use the instance of this callback on other screens? This is my message.json data model [ { "title": "Title 1", "body": "Lorem ipsum dolor sit amet. " }, { …
Nikash Deka
  • 427
  • 2
  • 4
  • 15
2
votes
1 answer

Serializing Foundation and non-foundation types to JSON in swift

I'm trying to serialize two different types of object to JSON, but I've only been able to do so using JSONEncoder for one, and JSONSerialization for the other. One is a simple Int, which I serialize as follows: let ticket: [String:Any] = ["ticket":…
kyrers
  • 489
  • 1
  • 6
  • 22
2
votes
1 answer

Send Notification to Multiple FCM Tokens

I have a class (PushNotificationSender). This class holds one function called sendPushNotification which takes in an FCM Token, Notification title, and Notification body. I have used it to successfully send a notification to one user, given that I…
2
votes
2 answers

How to use Swift's JSONSerialization when JSON returns a single string

So this is likely a very basic question, but I was curious how you would handle parsing a JSON object that returns as a single string using JSONSerialization in Swift. So I'm playing around with a free Harry Potter API and noticed that one of the…
nix.codes
  • 388
  • 2
  • 20
2
votes
1 answer

'NSInvalidArgumentException', reason: 'Invalid type in JSON write (__SwiftValue)'

I am getting the following error when I try to encode an object. 'NSInvalidArgumentException', reason: 'Invalid type in JSON write (__SwiftValue)' The definition of this object is as under:- public struct Item: Codable { public var _id: Int …
Ankur Israni
  • 23
  • 1
  • 3
2
votes
1 answer

Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 1." UserInfo={NSDebugDescription=Invalid value around character 1. swift 4

I got response from api via postman { "status": "1", "error": false, "message": "Your order has been placed successfully" } I called api and pass the params which required to call api. The code is giving an error "Invalid value around character…
Sanjay Mishra
  • 672
  • 7
  • 17
2
votes
1 answer

JSONSerialization.jsonObject isn't accepting my parameters

I'm attempting to Promise a Json object. However, JSONSerialization.jsonObject isn't accepting any of my parameters.. class func deserialize(data: Data) -> Promise { let deserialized = try! JSONSerialization.jsonObject(with: data, options:…
Konrad Wright
  • 1,254
  • 11
  • 24
2
votes
1 answer

How do I POST raw NSData as well as some NSStrings to my server?

I have a large piece of NSData I want to send to my server, but I also want to send a string dictionary of string keys mapped to string keys. How do I POST both in the same request? Almost all guides show wrapping it in an NSDictionary then using…
Doug Smith
  • 29,668
  • 57
  • 204
  • 388
2
votes
3 answers

Parse JSON Data Array with Swift 4

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…
Jacobi
  • 21
  • 1
  • 6
2
votes
1 answer

Crash when accessing Object properties after decoding from JSON

I have decodes JSON value into object. The object looks as expected, but when I try to access it's property. let jsonData = try JSONSerialization.data(withJSONObject: JSON, options: []) let decoder = JSONDecoder() let doctor = try!…
Luda
  • 7,282
  • 12
  • 79
  • 139
2
votes
0 answers

NSJSONSerialization returns NSNumber(double) causes failure comparing to NSNumber(Int64)

I have an Int64 (long-long) uniqueID passed as a number in a JSON file. { "id1" : 4627596562884205957 } The NSJSONSerialization always returns an NSNumber (double) in the NSDictionary property. This should be an Int64 number NSNumber (long-long),…
Jim Leask
  • 6,159
  • 5
  • 21
  • 31
2
votes
1 answer

How to create JSON from Model in ios Swift 3

I have created model class for the user as below. public class SignUpUser { public var fullName : String? public var id : Int? public var city : String? public var email : String? public var address : String? public var…
Scorpion
  • 6,831
  • 16
  • 75
  • 123