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
3
votes
5 answers

Getting null from NSDictionary when NSJSONSerialization is being used

I am new to developing and stackoverflow please help me. i am trying to do a simple application where the YQL link is used to get local data and display it in table format. For that i am converting the data into dictionary , later i want to send it…
3
votes
3 answers

JSON Objective-c - Objects and Arrays Combination

My JSON url is http://api.kivaws.org/v1/loans/search.json?status=fundraising My Objective- code displays page_size : 20 using the following code NSData *allCourseData=[[NSData alloc] initWithContentsOfURL:[NSURL…
user580950
  • 3,558
  • 12
  • 49
  • 94
3
votes
1 answer

Initialize Swift class with AnyObject? from NSJSONSerialization

I am using NSJSONSerialization in Swift 1.2 to parse some json that is returned from an API response. var err: NSError? let opts = NSJSONReadingOptions.AllowFragments let json: AnyObject? = NSJSONSerialization.JSONObjectWithData(jsonData!, options:…
wigging
  • 8,492
  • 12
  • 75
  • 117
3
votes
2 answers

Getting error in JSON parsing with array in iOS

I am newly to iPhone, basically in my application I am parsing below JSON model and need to save it in my custom Entity class. JSON model : { "Products": [ { "Pcs": [ { "product_id": 2, …
Anand Gautam
  • 2,541
  • 3
  • 34
  • 70
3
votes
2 answers

How to handle PHP errors in Swift

I'm using PHP & JSON to extract some data from a database. This is my PHP file
Machina
  • 252
  • 2
  • 13
3
votes
2 answers

Other options than NSJSONWritingPrettyPrinted?

I convert a NSDictionary to JSON NSData with the following line: NSData *jsonData = [NSJSONSerialization dataWithJSONObject:answers options:NSJSONWritingPrettyPrinted …
Raptor
  • 53,206
  • 45
  • 230
  • 366
3
votes
0 answers

The error parameter in dataWithJSONObject:options:error:

What can happen in the error parameter of + (NSData *)dataWithJSONObject:(id)obj options:(NSJSONWritingOptions)opt error:(NSError **)error It's a class method of the NSJSONSerialization class. The NSJSONSerialization class reference specifies that…
wmsschlck
  • 85
  • 1
  • 10
3
votes
3 answers

Get JSON in Swift

This is my code to get JSON, and it's work with this url I found on an other questions : http://binaenaleyh.net/dusor/. But, when I use it with this url : http://www.netcampus.fr/api/schools, it didn't work at all. I have an error who said :…
1L30
  • 259
  • 2
  • 4
  • 14
3
votes
1 answer

Object is subclass of NSMutableDictionary but crashes on mutate method (NSJSONSerialization)

Run this code: NSData *jsonData = [@"{\"foo\":\"bar\"}" dataUsingEncoding:NSUTF8StringEncoding]; id result = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil]; if ([result isKindOfClass:[NSMutableDictionary class]]) { …
3
votes
2 answers

How to iterate through a simple JSON object in Objective-C?

I'm very new to Objective-C, I'm a hardcore Java and Python veteran. I've created an Objective-C script that calls a URL and gets the JSON object returned by the URL: // Prepare the link that is going to be used on the GET request NSURL * url =…
user1504605
  • 579
  • 5
  • 19
3
votes
2 answers

NSJSONSerialization and Emoji

I'm currently trying to POST some JSON containing emojis to a python API. I tried feeding the NSJSONSerialization directly with the string containing the emojis from my UITextField but the serializer crashed with no meaningful…
Tim Specht
  • 3,068
  • 4
  • 28
  • 46
3
votes
1 answer

Convert NSDictionary containing NSArray to JSON

I have a NSDictionary containing a few different objects, among which is a NSArray. Elements in the array are NSDictionary-representations of a custom object. I have renamed the properties and removed some others for simplicity. First I try to…
pajevic
  • 4,607
  • 4
  • 39
  • 73
3
votes
2 answers

NSJSONSerialization - "Unexpected end of file during string parse"

i have some wired issue when Parsing some REST-Response. The problem is, that i can't reproduce it . Sometimes it happens, and I have no corresponding information in the error logs. Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t…
3
votes
2 answers

iOS Send JSON data in POST request using NSJSONSerialization

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…
ninefifteen
  • 931
  • 1
  • 10
  • 16
3
votes
2 answers

Exception while stubbing method with pass-by-reference in OCMockito

I'm trying to use OCMockito to stub an NSJSONSerialization method. I thought I had a solution, but it turns out it causes this exception: *** -[__NSArrayM objectAtIndex:]: index 2 beyond bounds [0 .. 1] Here's what I was doing: Class mockClass =…
Cruinh
  • 3,611
  • 4
  • 38
  • 45