-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Added JSON serialization mechanism #137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
return str.dataUsingEncoding(NSUTF8StringEncoding)! | ||
} | ||
|
||
private class func JSONSerialize(object: AnyObject, newIndent: String, newLine: String, space: String, indentation: String = "") throws -> String |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
object needs to be of type Any not AnyObject since this will not work for value types.
I think we'll also need some unit tests added for this before we accept it. |
@phausler fixed the AnyObject -> Any but I also added in code to handle NSDictionary and NSArray because otherwise these objects weren't being handled. Bridging between [AnyObject] and NSArray doesn't work in the current version and that needs to be fixed. |
There seem to be a few compile failures with this still
and the tests also fail to compile
|
plutil could also use this, right? |
plutil should have json support but it does not yet have that part of the implementation |
@phausler yeah I understand. I just meant that when |
Yup, that's exactly what plutil on Darwin does. |
@manavgabhawala What's the status of this PR? I'm in need of this and would be happy to help out, however there haven't been any commits in two months. |
@czechboy0 Pushed changes to make it work with the latest swift build snapshot. |
@swift-ci Please test |
@phausler one test case was failing because the ordering of the keys of the dictionary was different on Linux builds. But I updated the test cases so that the ordering of keys doesn't impact the result of the test cases. Please test again. |
@swift-ci Please test |
…orts Remove `@testable import` and `-enable-testing`
Adds initial code for (almost) RFC compliant JSON serialization mechanism to convert JSON (in the form of AnyObject) to NSData. Works with PrettyPrinted option too.