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

JSON parsing using NSJSONSerialization in iOS

I am parsing a JSON in my code. But I am getting some unexpected issues while retrieving data of parsed JSON. So let me explain my problem. I have to parse following JSON data using xcode. This is what data to be parsed looks like while I hit same…
Nayan
  • 3,014
  • 2
  • 17
  • 33
6
votes
1 answer

NSURLSessionDownloadTaskDelegate JSON response

I am running a background NSURLSession session and i am trying to figure out a way to get the JSON response out of one of the NSURLDownloadTaskDelegate callbacks. I have configured my session to accept JSON responses. NSURLSessionConfiguration…
lost found
  • 329
  • 1
  • 3
  • 12
6
votes
1 answer

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

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…
John Rogers
  • 2,192
  • 19
  • 29
5
votes
6 answers

How do I fetch data from URL, using xcode 4.3.1 with NSJSONSerialization Class Reference

I am trying to get my head around the NSJSONSerialization Class Reference. In the lack of a code-example at the developer.apple.com website, I´m lost. There are millions of examples all around the web with other json libaries, but I haven´t been…
CustomCase
  • 247
  • 1
  • 4
  • 15
5
votes
0 answers

Encoding problems when requesting Google suggestions

I'm trying to get Google Suggestions to work for Greek but I get an error if the suggestions contain characters other than english. If the query is "magni" for example the response will contain a greek word "μαγνήσιο" as a suggestion. Try it The…
Vulkan
  • 1,004
  • 16
  • 44
5
votes
1 answer

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

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!, …
iAkshay
  • 1,143
  • 1
  • 13
  • 35
5
votes
0 answers

Memory Leak in NSJSONSerialization

I have started looking into memory leaks recently and I'm not able to figure out why JSON serialization is causing a leak. class func convertDataToDictionary(resultData: NSData) -> [String:AnyObject]{ do{ let json = try…
ebby94
  • 3,131
  • 2
  • 23
  • 31
5
votes
1 answer

How to create true/false in JSON in Objective-C

How do I get true/false (instead of "true"/"false") in json from a NSDictionary using NSJSONSerialization dataWithJSONObject? What keys should I store in the dictionary to get that?
Boon
  • 40,656
  • 60
  • 209
  • 315
5
votes
2 answers

NSJSONSerialization with NO Options

I've used this in several projects... [NSJSONSerialization dataWithJSONObject:someObject options:0 error:nil] but I don't know how to specify no options. This is both for reading and writing. I saw an example somewhere where the person had used a…
Fogmeister
  • 76,236
  • 42
  • 207
  • 306
5
votes
1 answer

NSJSONSerialization output number as float?

I'm using NSJSONSerialization to convert a dictionary into JSON. If I include an NSDecimalNumber ( == 0 ) in that dictionary it outputs as 0. This is wrong. 0 is an int. I need it to output as 0.0. This is what I'm doing: NSDecimalNumber *decimal =…
Thomas Clayson
  • 29,657
  • 26
  • 147
  • 224
5
votes
5 answers

Parse json with NSJSONSerialization class using objectForKey in iOS

I am new in iOS development. I use this code to connect to my REST Web Service and fetch data in Json format. NSString *url=@"URL_Address"; NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:url]]; …
Ali
  • 9,800
  • 19
  • 72
  • 152
4
votes
1 answer

solidity TypeError: Object of type set is not JSON serializable

I ran the code in VSCode and got a TypeError: Object of type set is not JSON serializable. I just start to learn to code, really don't get it, and googled it, also didn't know what does JSON serializable means. from solcx import…
mike515
  • 183
  • 1
  • 14
4
votes
1 answer

How to create and post json to web service Objective c

I try to convertNSDictionary to JSON data and sent it to PHP.server in "POST" request with setHTTPBody. I received a null from the server when I sent from my app, but when I send the JSON from PostMan I receive the objects. Where am I wrong ? -…
Roei Nadam
  • 1,780
  • 1
  • 15
  • 33
4
votes
3 answers

How to convert NSObject class object into JSON in Swift?

I have var contacts : [ContactsModel] = [] and class ContactsModel: NSObject { var contactEmail : String? var contactName : String? var contactNumber : String? var recordId : Int32? var modifiedDate : String? } Now in contacts…
Shrikant K
  • 1,988
  • 2
  • 23
  • 34
4
votes
1 answer

What is the more elegant way to serialize my own objects with arrays in Swift

I have a classes that looks like this: class Foo { var bar = Int() } class Bar { var baz = String() var arr = [Foo]() } and I have an object of Bar structure that I need to serialize to JSON: let instance = Bar() What is the more…
FrozenHeart
  • 19,844
  • 33
  • 126
  • 242