JSON Warning in Flickr Photo Manager - ios

I am getting a warning in my iOS app. It doesn't seem to be affecting performance in iOS 6 but my app is crashing when loading the photos from Flickr in iOS 7 beta 2 and I'm not sure if it's an issue with the beta or perhaps something to do with this warning but I'd like to get rid of the warning anyway. Any help?
Implicit conversion from enumeration type 'enum NSJSONWritingOptions' to different enumeration type 'NSJSONReadingOptions' (aka 'enum NSJSONReadingOptions')
NSError *error;
NSDictionary *results = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONWritingPrettyPrinted error:&error];

Pretty simple !! Just re-read the warning again. It says you are passing NSJSONWritingOptions option in options parameter while it expects NSJSONReadingOptions.
Change your line of code as below:
NSDictionary *results = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
It should help you.

Core Background works on iOS 6 and iOS 7 beta 1,2. The project was inspired by the Yahoo Weather iOS App. ObjectiveFlickr is leveraged for Flickr integration.
https://github.com/justinmfischer/core-background

Related

Not all keys work when converting JSON String to NSDictionary

I'm using the following code to convert a JSON string literal to an array holding an NSDictionary for each item:
NSString* json = #"[{\"name\":\"Item 1\",\"id\":\"999\",\"lang\":\"en\",\"type\":\"A\",\"version\":15}]";
NSData* data = [json dataUsingEncoding:NSUTF8StringEncoding];
NSArray* values = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
After removing the app from my test device, the app started crashing when attempting to access, in a for loop values[i][#"name"]. When viewing values in the inspector, I see the following:
values = (NSArray *) #"1 object"
[0] = (__NSDictionaryM *) 5 key/value pairs
[0] = (no summary) : #"Item 1"
[1] = #"id" : #"999"
[2] = #"type" : #"A"
[3] = (no summary) : (long)15
[4] = #"lang" : (no summary)
When expanded further, the keys that should be name and version are both shown to be the type (__NSCFConstantString *)
This was working prior to removing the app from the device, and no changes have been made to this section of the code.
Any ideas on what could be causing this, or better ways to convert the json string to a dictionary?
UPDATE: I changed "name" and "version" to "game" and "gersion", and it worked perfectly.
After attempting to debug this for several hours, my supervisor and I decided to restart the MacBook I'm developing on. This resolved the runtime issue, and the code in my question is once again working as expected.
We are still unsure what caused the device to get into this state, since running "Clean Build Folder" several times, closing and relaunching XCode, and restarting the iPad did nothing to help us.
I considered removing the question, but since we don't know what caused this I figured someone else may run into this issue in the future and this answer could help them. If anyone could provide some insight into what may have brought this situation about, I will gladly accept your answer.

Why does RKNSJSONSerialization crash on iOS 6?

I'm seeing a crash in RKNSJSONSerialization on iOS 6 only - not on iOS 7. I'm using RestKit 0.20.3 and it happens fairly consistently for me. Even when I make the same request and get the same response for iOS 6/7, it works fine on iOS 7 but crashes on iOS 6.
Here's the crash - it's an EXC_BAD_ACCESS: http://crashes.to/s/2610b639062
The relevant (crashing) line in RestKit's RKNSJSONSerialization is the return:
+ (id)objectFromData:(NSData *)data error:(NSError **)error
{
return [NSJSONSerialization JSONObjectWithData:data options:0 error:error];
}
So perhaps it's not RestKit at all - perhaps it's NSJSONSerialization.
I profiled the app with the Zombies tool and found this:
"An Objective-C message was sent to a deallocated 'CFString (immutable)' object (zombie) at address: 0x16851250."
Am I doing something wrong?
I've resolved this. The issue was that my JSON had duplicate keys in it, and iOS 6 couldn't handle that. The solution is to remove the duplicate keys from the JSON before trying to parse it with NSJSONSerialization on iOS 6. Apparently Apple has resolved this issue on iOS 7, since it doesn't crash there.
Related: NSJSONSerialization bug?
This seems to be a typo.
Assuming there is an object called error of type NSError, the call JSONObjectWithData: takes a pointer to a pointer as the last argument, i.e. with &.
return [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];

Parsing JSON using NSJSONSerialization

I am currently going through the Pragmatic iOS 6 book, and am having trouble understanding the following line of code explained in chapter 3 under the section about GCD:
NSJSONSerialization *jsonResponse = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError];
//... some code here
NSArray *tweets = (NSArray *) jsonResponse; //<-- this line
Is it saying that the NSJSONSSerialization object could automatically return an instance of NSSArray, which is then stored in the tweets? I checked the Apple docs, but only saw items on restrictions using NSJSONSerialization, but not what objects it could then get converted to.
Thanks!
NSJSONSerialization can take a chunk of JSON data and turn into objects and it can do the same in the other direction that is by taking objects and converting them into the JSON data.
For easy understanding of NSJSONSerialization and interaction with Twitter, i would recommend you to use THIS and THIS tutorials.
Hope this helps!

exception error with json in xcode

I'm beginner in ios. I developing a call with JSON for access a data and insert after on UITableView.
In this point on my code
NSDictionary * dict = [[CJSONDeserializer deserializer ] deserialize:jsonData error:&error];
When compiling I obtained this error
2013-02-07 15:49:48.078 comercMobil[12933:c07] +[CJSONScanner scannerWithData:]: unrecognized selector sent to class 0xe7b8
2013-02-07 15:49:48.080 comercMobil[12933:c07] Exception +[CJSONScanner scannerWithData:]: unrecognized selector sent to class 0xe7b8
any suggestions? thanks for all
A couple of things:
This is not a compiler error, but rather a runtime error.
I don't think this is the line that's causing this error, since you're not calling scannerWithData here. I'd search your source for a reference to scannerWithData.
But, I agree with Sean that you should consider just using NSJSONSerialization.
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data
options:0
error:&error];
Or, if you need support for iOS prior to version 5.0, SBJSON is very popular.

Issues getting json from webserver in iOS5

I have a app that receive a feed from a server through json.
I have been building it for iOS5, but in the last weeks testing with iOS6. I tested today with a iOS5 device, and everything crashed.
The code looks like this:
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:#"http://www.myserver.com/news.json"]];
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
It worked without problems, but now it returns a null. The data is not null.
Cocoa error 3840 means
The data couldn’t be read because it has been corrupted. (No string
key for value in object around character 2.)
You should check your json with a validator like http://www.jsoneditoronline.org/ or http://jsonformatter.curiousconcept.com/
The issue was a duplicated key from the webserver. Now it works.
But it strange that the error is trigged in iOS5 and not in iOS6.

Resources