Environment: iOS 4.3+ using Xcode 4.3+
I'm always getting an iOS/Xcode crash when I implement the following string that returns data with nulls in it:
[NSString stringWithContentsOfURL:myURL encoding:NSUTF8StringEncoding error:&error];
NSDictionary *myResult = (NSDictionary *)[myString JSONValue];
The result:
-[NSNull isEqualToString:]: unrecognized selector sent to instance 0x17315e8
When the data stream contains no nulls (mostly), it works fine.
Is this a known problem?
Any remedy?
You can also fix the data coming in from the source. In almost all of my web service interaction, I use COALESCE on queries and SP's to make sure that the data coming out is always consistent.
Related
My YYModel is managed by cocoapods. I use YYModel to convert json to model.There is my code where use YYModel:
for (NSDictionary *dic in labelArray) {
CQMenuButtonModel *model = [[CQMenuButtonModel alloc]init];
[model yy_modelSetWithDictionary:dic];
[modelsArray addObject:model];
}
It crashed at [model yy_modelSetWithDictionary:dic];,and the console showed:'-[CQMenuButtonModel yy_modelSetWithDictionary:]: unrecognized selector sent to instance 0x18b47d20'
However, it work fine on iOS9 and iOS10.
At first I think maybe the newest YYModel doesn't fit iOS8, so I change the YYModel's version to 0.9, However,it's crash on iOS8 too.
What confused me most is that why it crash on iOS8 but work fine on iOS9 and iOS10,What's more,I really don't understand why console show me :unrecognized selector sent to instance 0x18b47d20
I replaced YYModel with JSONModel at last then it work fine.
I am using GDataXMLDocument. I need to parse very simple XML string. When I try to init XML with string I receive error:
-[myObj dataUsingEncoding:]: unrecognized selector sent to instance 0x7afb5690
My string is:
<rootNode>
<detail1>value</detail1>
<detail2>value</detail2>
<detail3>value</detail3>
<detail4>value</detail4>
</rootNode>
The line of the error is:
NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding];
where I need to encode my string no NSData, so I can init my parser with it.
I suppose the problem is in NSUTF8StringEncoding, but I can not understand why!
I am using ARC with NON ARC for GDataXML set in compilation options.
How to solve this?
P.S. I have a remark which might be important. I receive an array from SOAP service. I used sudzc.com tool to create my classes. The SOAP service send to me array of structures. When I receive data using po command see what is inside and I decided that it consists of NSArray with XML sting inside. In general I extract each element of an array and try to parse it as XML to extract data I need.
May be I am wrong and that is the reason for that error.
I don't know why but I fix it casting once again to NSString with format using:
NSString *properStr = [NSString stringWithFormat:#"%#", str];
I am not sure why I need this, but it is wotking now.
What I am trying to do is convert a document to an dictionary and then iterate that dictionary to see what's inside, but I am having the following problem when trying to convert the document.
I have the following code:
CBLDocument *document = row.value;
NSDictionary *dict = document.properties;
the xCode is always complaining "[__NSCFDictionary currentRevision]: unrecognized selector sent to instance 0x90c4150" when running to the second statement.
I have also tried NSDictionary *dict = document.currentRevision.properties;
It's not working either.
Could anyone help me with that?
OK, it turns out row.value is not a document(is actually a dictionary), but nobody tells me that when I emit(#[somekey], doc); The doc (which is the value) is actually a dictionary instead of a document.
But weird though the compiler did not complain when assigning the dictionary to a CBLDocument.
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.
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.