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
Represent JSON as string even if Swift can't do it #610
Conversation
hm, not sure if I follows. Is this what you're looking for? Unless your intention is to convert So if the api is asking you to send But doing it in the framework level seems a bit to specific. What do you think? 😄 |
Yes, I'm trying to address the conversion of To you, how does the value is
and
convey the idea that there's a key |
Thanks for the quick reply, In you example, type IMHO, JSON dictionary is a type
Then with your example.
Hope I'm making sense here. 😄 |
I agree this is all very confusing. I've dig a bit into this, and found even more confusing things. I get your point that I also think we need to have something that fits the daily challenges of developers, so I don't think it's fine to not be able to serialize dictionaries with
Happy to learn/discuss anything I'm missing here! |
Is the discussion closed? What about having this as an optional way to cast to string? Like func rawString(
_ encoding: String.Encoding = .utf8,
options opt: [JSONSerialization.WritingOptions],
maxObjectDepth: Int = 10
) throws -> String? {
// then, if an option is passed to cast `nil` to `NSNull`, do it, else don't, like
// rawString(options: [.prettyPrinted, .castingNilToNSNull])
...
}
// and keep the original one for backward compatibility:
func rawString(
_ encoding: String.Encoding = .utf8,
options opt: JSONSerialization.WritingOptions = .prettyPrinted
) -> String? {
return rawString(encoding, options: [opt])
} |
sorry, I didnt close this on purpose, we cleaning the swift3 branch since we no long need it. |
Can you try pointing this to master branch? |
I'd definitely prefer to having a separate method or option doing this. Not sure if you can extend |
Ok I've rebased |
Let me see what I can do for the option |
I've changed things so that:
|
hey mate, sorry for the late reply. Try a couple times solve the conflict and merge this PR, but seems like I'm can't push to you repo. kylefang:SwiftyJSON/ (PR-610) $ gp gsabran PR-610:swift3 [0:32:59]
Counting objects: 299, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (294/294), done.
Writing objects: 100% (299/299), 57.89 KiB | 0 bytes/s, done.
Total 299 (delta 174), reused 0 (delta 0)
remote: Resolving deltas: 100% (174/174), completed with 14 local objects.
To https://github.com/gsabran/SwiftyJSON.git
! [remote rejected] PR-610 -> swift3 (permission denied)
error: failed to push some refs to 'https://github.com/gsabran/SwiftyJSON.git' Can you help, will merge this ASAP. |
Ah sure. Let me look at what has change on the main branch |
I've rebased |
👍 |
Swift cannot represent dictionaries with
nil
values as json (http://stackoverflow.com/questions/13908094/how-to-include-null-value-in-the-json-via-nsjsonserialization) and the current SwiftyJSON string representation that relies on the default swift JSON string representation will fail as way.Here I created a custom string representation that doesn't doesn't rely on the built in one, and can handle things with nil or values. I also added a few tests.