Comments (7)
Lots of thoughts, and it's something that I've been thinking about. I added callbacks to the serialization process, but that was relatively straightforward. But so far I haven't been able to come up with a clean and elegant way of adding callbacks to the deserialization process.
So, it's been on my radar, but I have yet to come up with something that I'm happy with. Unfortunately, I wouldn't expect this feature to get added any time soon. I'd much rather do it right then do it half-assed.
from jsonkit.
Totally makes sense. Just wanted to make sure it was somewhere on the long list (even if only the wish list :). Thanks for reading my message. Oh yeah when I saw the callbacks for serialization I got so psyched thinking there must be matching deserialization ones :)
On May 18, 2011, at 10:34 PM, [email protected] wrote:
Lots of thoughts, and it's something that I've been thinking about. I added callbacks to the serialization process, but that was relatively straightforward. But so far I haven't been able to come up with a clean and elegant way of adding callbacks to the deserialization process.
So, it's been on my radar, but I have yet to come up with something that I'm happy with. Unfortunately, I wouldn't expect this feature to get added any time soon. I'd much rather do it right then do it half-assed.
Reply to this email directly or view it on GitHub:
#25 (comment)
from jsonkit.
RE: the 2nd point regarding NSNull's, add the one-line i've included below inside _JKDictionaryAddObject() inside JSONKit.m after NSCParameterAssert() and you'll have the functionality you want for the NSDictionary category.
Caveat emptor! Be careful what you wish for. As johnezang explained in another issue, returning NSNull is a feature, not a bug. There is a very good reason why JSONKit is returning NSNull, as NSNull and nil means different things, representing different situations which you may have to cater for in your app.
static void _JKDictionaryAddObject(JKDictionary *dictionary, NSUInteger keyHash, id key, id object) {
NSCParameterAssert((dictionary != NULL) && (key != NULL) && (object != NULL) && (dictionary->count < dictionary->capacity) && (dictionary->entry != NULL));
if (object == [NSNull null]) { CFRelease(key); CFRelease(object); return; }
from jsonkit.
Thank you @FunkeeMonk. Your comment also helps me understand some of the things going on in JSONKit.
I would also want the arrays to work like this. Do you think this would work correctly? It looks right to me but I'd like a second (or third) opinion.
static void _JKArrayInsertObjectAtIndex(JKArray *array, id newObject, NSUInteger objectIndex) {
NSCParameterAssert((array != NULL) && (array->objects != NULL) && (array->count <= array->capacity) && (objectIndex <= array->count) && (newObject != NULL));
if(newObject == [NSNull null] || !((array != NULL) && (array->objects != NULL) && (objectIndex <= array->count) && (newObject != NULL))) { [newObject autorelease]; return; }
I've added object == [NSNull null]
to the beginning of the third line.
from jsonkit.
That last one didn't work. This did though. In the function static void *jk_parse_array(JKParseState *parseState)
I changed the state in the switch statement for nulls to this:
case JKTokenTypeNull:
if(JK_EXPECT_F((arrayState & JKParseAcceptValue) == 0)) { parseState->errorIsPrev = 1; jk_error(parseState, @"Unexpected value."); stopParsing = 1; break; }
if(JK_EXPECT_F((object = jk_object_for_token(parseState)) == NULL)) { jk_error(parseState, @"Internal error: Object == NULL"); stopParsing = 1; break; } else { arrayState = JKParseAcceptCommaOrEnd; }
break;
from jsonkit.
Adding rich deserialization callbacks could avoid the cost of creating intermediate dictionary objects when the desired result is an application-specific object instance. That might be more complicated than what's being proposed here, however, as it would extend to custom-deserializing container types instead of just simple values.
from jsonkit.
Yeah that could get pretty complicated. This library is already super complex and optimized. I got those darn nulls out so I'm happy :).
from jsonkit.
Related Issues (20)
- Any popular replacement for JSONKit? HOT 2
- BSD two-clause or three-clause license? HOT 2
- crash at JSONKit.m:2598:77 HOT 2
- Error in serializing NSNumber HOT 2
- Supporting gzip decompression
- Swift HOT 7
- can not use with xcode 7 HOT 4
- Xcode 7 Before is use JSONKit in Object but now not use JSONKit in Xcode 7 HOT 7
- crash with iOS9 Xcode7 HOT 5
- Should be #import <JSONKit/JSONKit.h> or <GCJSONKit/JSONKit.h>? HOT 1
- please ignore
- Crash when NSDictionary to String json format. HOT 1
- about convert json to NSDictioanry (error if json string contains double field) HOT 7
- JsonKit message JSONDataWithOptions crashes in macOS Sierra HOT 1
- JSONKit Installation error in X-code 7.3.1 iOS 9.3 HOT 1
- iOS TRAP_TRACE crash
- JSONKit semantic issue after updating the pod HOT 3
- Tagged pointer format changes in iOS 14 break JSONKit on ARM64 HOT 8
- @serkrapiv Not necessarily verboten, just that they must be escaped. The first paragraph of 2.5 Strings says: HOT 1
- Yea
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsonkit.